odiggity
odiggity

Reputation: 4127

Force close doesn't exit android application, instead opens a previous activity in very buggy state

The problem that I'm having is when running my android app, if I run into a force close error or pause the application with a breakpoint in debug mode and then press 'stop', the app doesn't quit, instead the first activity on my activity stack is opened but it is in a very buggy state. The activity is a library of books and when it is opened after the force close or by stopping, all of the users books are gone, the labels on the options menu are gone (although the icons are still there) and almost any action results in a force close.

So basically I'm wondering why stopping the application in debug mode, or running into a force close doesn't shut down the whole application and instead opens the first activity in a very buggy state.

I can't give specific code because the force close only happened once and I didn't get the stack trace. I realize this is a very generic question and I understand if it's too little information to go off of I just wanted to see if anyone else had run into something similar.

Edit: It seems as though force close just closes the current activity and tries to open the previous activity on the stack. However somehow my application context is getting destroyed so when the previous activity opens and looks for information in the application context, such as books in the user's library, there is nothing there.

Upvotes: 3

Views: 2187

Answers (2)

KeenMonk
KeenMonk

Reputation: 432

When you run into a force-close, your app's process is killed. If your activity stack had an activity behind the one that crashed, it is restarted in a new process. When the process dies, so does the application context. The new process creates a new application context, which is why you're not seeing your data in there.

See http://groups.google.com/group/android-developers/browse_thread/thread/b274cfa64b17f535?pli=1 for a discussion on this.

One way to address your specific problem is to add a flag in your Application object, that you explicitly set to true after your shared data is loaded. You can then check for this flag in your Activity's onCreate() to confirm that the data is available. If the flag is false, you can call finish()

Upvotes: 2

Manish Burman
Manish Burman

Reputation: 3079

This has happened to me a few times. I've noticed that when I have a stack of activities and I start the second without closing the first, then a "force close" on the second only stops the second activity. Since the first activity is still running, it comes to the forefront.

Example. Activity A is running. Clicking on a button opens activity B. (I didn't finish() activity A) Activity B for some reason 'force closes'. Activity A comes into view since its still running.

Upvotes: 0

Related Questions