Question

My app design is like this, i have an sqlite database, and a fragment which renders the data from database with help of Loader.

To launch my application, in Activity A first i will show a welcome screen, authenticate the user, initialize DB with help of activity A instance and then i finish it off. i will finish() this activity because from activity B, if user press back button it should end there itself.

Later i will move to second screen i.e Activity B. here i will load the data with help of loader (cwac by commonsware) & display content.

If user press home button, and resumes after sometime. My app crashes but crash log just says

06-04 20:39:52.569: W/dalvikvm(18544): threadid=11: thread exiting with uncaught exception (group=0x40c68a68)
06-04 20:39:52.569: W/dalvikvm(18544): threadid=12: thread exiting with uncaught exception (group=0x40c68a68)

To check i put log message & got to know that DB handler is coming as NULL & even activity A object is also NULL. This is because while launching Activity B i will finish the A activity.

To test, i just removed finish() in Activity A, still my app crashes. just it says unhandled exception. DB object is NULL & A activity object too..

Note: only onsaveinstance of Activity B calls, but not A, even though i removed finish() on activity A How to handle these kind of scenarios.?

Was it helpful?

Solution

If user press home button, and resumes after sometime. My app crashes but crash log just says

There should be a Java stack trace associated with an error, not just some warnings.

got to know that DB handler is coming as NULL

I assume that the "DB handler" is a singleton. This indicates that your process was terminated while it was in the background. This is perfectly normal behavior for Android.

even activity A object is also NULL

There should not be an "activity A object". Do not put an Activity in a static data member.

How to handle these kind of scenarios.?

Understand that your process can be terminated at any time, for any reason. If the user returns to your app via something other than your launcher icon (e.g., via the recent-tasks list), Android will attempt to return the user to where the user had been within your application. This means that Activity A is not necessarily going to be created. You need to handle this case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top