UiApplication is not able to maintain its state - blackberry

I am developing an application to do the following things.
Tracks the Incoming/Outgoing Call.
If user attends to the call, after disconnected the call a Screen will pop-up.(User Have to fill some info and content will save in (Sqlite) database)
Now what I am doing is :-
First Make different entry point (autostartup) & this is the Entry-point of the application. (logic is working fine)
Implement Phone-listener that tracks Incoming/Outgoing Calls (logic is working fine)
When a call is disconnected, detail Screen will pop-up, User can fill up the screen. (logic is working fine)
But the Problem is when user Receives/Do calls and return back to the application, application isn't able to maintain variable states (like File Connections, Global variables that uses in application) they all become reset. This issue I am getting only on the Incoming/Outgoing Call time.
I used Run-time persistence storage but its not working in case of records insertion into the database.
I reinitialize the Database class but it's not working at all.
Please let me know, Why I am getting this issue.

"application can't able to maintain variable states (like File Connections , Global variables that uses in application ) they all become reset"
I presume that you are trying to maintain these 'global' variables as 'static' variables. Remember that static variables are only global to the same Application instance. In this case, the Phone Listener is invoked under a different application - the phone application - and so these variables are different to those that you see in your application.
To resolve this, I recommend doing two things:
a) Use RuntimeStore to provide a place to store shared (global) variables:
http://supportforums.blackberry.com/t5/Java-Development/Create-a-singleton-using-the-RuntimeStore/ta-p/442854
b) Have your listeners do as little as possible, use global events to pass the required information back to your application in your Application's context:
http://supportforums.blackberry.com/t5/Java-Development/Global-Events-and-Global-Event-Listeners/ta-p/444814
But perhaps I have not understood your problem clearly, if not, please clarify.

Related

Rails Light Service: Reduce the LightService::Context afterwards

I'm using the LightService gem for Rails. I have created a few services to collect data for me. In one case, I want this data to be collected based on previously updated values.
To do this, I created an Organizer service that first calls an Update service, which in turn updates some properties. Then the Organizer calls another service which gives me the data based on these updated properties.
The problem now is that my LightService::Context now contains the promises of both called services. This is correct in other cases, but in this specific case I only need the data of the second service in the LightService::Context and the possibility to continue calling the success? method.
Is there a way to tell Rails
or LightService that I only want the LightService::Context of the second service?
Many thanks in advance

Store global strings in iOS in Swift for app-wide use

I am designing an app which has a login screen. When the user enters username and password, a call to web service is done which returns a token on successful login. Now I need to send this token to every HTTP call inside different screens across the app.
I want to achieve similar functionality like this: Where to store global constants in an iOS application?
As there won't be any .h and .m files in Swift, how do I store these global strings (Note these are not constants, these are global variables) that I need to be able to access in any view controller
This is what exactly I wanted: Sharing strings and variables throughout ios app
I am able to share strings such as apikeys, tokens by using NSUserDefaults
saving:
NSUserDefaults.standardUserDefaults().setObject("apistringhere", forKey: "apikey")
NSUserDefaults.standardUserDefaults().synchronize()
getting:
NSUserDefaults.standardUserDefaults().objectForKey("apikey")
First off, using global variable is not the right answer to most questions. You should rather have an object that takes care of communicating with the web service and that object should also be responsible to tracking login state and tokens. If URLs changes, you'd have to only change them in one place and the code processing the data doesn't need to care where the data come from.
That being said, you can declare a global variable or constant in Swift just by declaring at the top level scope of a file, outside of any functions, methods, closures or types. You can also modify the visibility of the variable/constant with the access control keywords.

Rails model global variable

I want to implement a functionality of messages to display on different pages on my site.
I have created a model for this that contains fields, say page, message, active. If active=false the message will not be displayed. This works fine.
Now I want to add a capability to turn all messages on/off for some time. I don't want to update each message and set active=false because 1) there can be a lot of messages, 2) I would have to save which messages were active/inactive at the moment of turning off to restore the initial state when turning back on.
This would be very handy if I could use new "class-wide" variable ##active in my model. However, using multi-thread app (I use unicorn) can cause troubles because ##active will not be shared over all processes.
I was not able to google a good solutions for this, maybe someone can help?
Perhaps create an environment variable called DISABLE_ALL_MESSAGES and then override the message#active method to refer to ENV["DISABLE_ALL_MESSAGES"]:
def active
ENV["DISABLE_ALL_MESSAGES"] && super
end
Another option would be to store the setting in the database and refer to it in a similar manner.
Try setting preload_app=true in your unicorn configuration. This lets unicorn master process to preload the app and all the other workers share the loaded data structure. You might want to move to Ruby Enterprise Edition to share memory across processes.

Server Context Variable

I need to set up a context variable for rails in a way that I can store it and use on all controllers and actions in my app.
Basically it's a server that have several games. The user chooses 1 game and that goes on current_game. Depending on the value of current_game the app loads different stuff from the data base.
Is there a way I can make it?
May be you can using session variables, read the documentation !

iPhone Data Best Practices - caching vs remote

I'm developing an iPhone app that uses a user account and a web API to get results (json) from a website. The results are a list of user's events.
Just looking for some advice or strategies - when to cache and when to make an api call... and if the iPhone SDK has anything built in to handle these scenarios.
When I get the results from the server, they populate an array in a controller. In the UI, you can go from a table listing view, to a view of an individual event result - so two controllers share a reference to the same event object.
What gets tricky is that a user can change the details of an event. In this case I make a copy of the local Event object for the user's changes, in case they make an error. If the api call successfully goes through and updates that event on the server, I take these local changes from the Event copy and set the original Event object to match with setters.
I have the original controller observing if any change is made to the local Event object so that it can reflect it in the UI.
Is this the right way of doing things? I don't want to make too many API calls to reload data from the server, But after a user makes an update should I be pulling down the list again with the API call?
...I want to be careful that my local objects don't become out of sync with the remote.
Any advice is appreciated.
I took a similar approach with an app I built. I simply made a duplicate version of the remote data model with Core Data, and I use etags on the backend to prevent sync issues (in my case, it's okay to create duplicate records).
It sounds like you're taking a good approach to this.
Some time back, I developed an iOS app where in, I had almost same requirement to store data on server as well as locally to avoid several network call and also user can see their information without any delay.
In that app, user can store photos, nodes, checkIns and social media post and with all this data, app can form a beautiful timeline. So what we did was, we had everything locally and whenever user phone come in some WIFI zone, we start uploading that data to server and sync both (local and remote) databases.
Note this method works well when only one user can access this data.

Resources