I am new to android development. I made an application on android but i am facing a crash after my app long sleep in the background.i tried singletons and sub application but both of them leads me to a crash after long sleep.
The configuration that i am saving is a list of objects many of them.also these configuration should be accessible in the whole application.
any Idea how to handle this? I'd searched the websites looking for answer but with no luck.since the Shared preference only for String,boolean ,integer and floats....also I am targeting android 2.1 and higher.
Is there any Easy procedure to that avoiding me to change the whole application mechanism ?
Thanks
I have had bad experiences with Singletons in Android. The problem is that the Singleton can outlive the application, if the application is destroyed but the jvm is not the Singleton's state is not reinitialized when the activity is restarted in the same jvm, i.e. with the same instance of the singleton (connected to the old class loader). Does this explain the behavior of your application.
A possible solution is to use the the Application instance created by Android. Its life cycle is managed by android and you can manage the state in onCreate(), ... Since API level 14 there are also activity life cycle callbacks. Look here for more information: http://developer.android.com/reference/android/app/Application.html#registerActivityLifecycleCallbacks%28android.app.Application.ActivityLifecycleCallbacks%29
If I need a global variable and the database or shared preferences are not appropriate solutions I usually use the Application instance to store the state. You can get the initialized Application or Service instance by calling
in your activity or service, e.g. in onCreate(). You initialize your instance of MyApplication (which extends Application) in its onCreate() method.