Getting a force close error on receipt of a text message AFTER app has been killed
Have an app that carries out a number of tasks when the phone receives on sms message, and they all work fine. However, if I exit/ kill the app, I get a force close error when I receive an sms message.
It's almost like the app is still somehow running/ some methods like "onReceive" are still cached in memory. I need to ensure when the application is exited, that it is properly exited and the phone doesn't give the force close error. Can anyone advise?
Here is the code for exiting the app which seems to work fine. (When I press back on the phone when inside the app and开发者_运维百科 am back at android home screen, when I check advanced task killer; it is not listed)
@Override
public void onDestroy() {
super.onDestroy();
System.runFinalizersOnExit(true);
System.exit(0);
}//end onDestroy method
You should read some about how Android works:
- Activity especially Activity Lifecycle part
- Application Fundamentals
- Tasks and Back Stack
Try to look at the system logs (adb logcat) there may be some messages about not unregistered/leaked recievers or something else similar.
Looks like you have some reciever that rely on some data, what was destroyed/nulled after your app shutdown.
Why are you doing System.exit(0)? Also runFinalizersOnExit
is marked deprecated and unsafe in documentation.
Seems like you need to do unregisterReceiver(BroadcastReceiver)
in onStop
or onDestroy
method depending on your needs.
It seems quite obvious that it is FYPSpeakerActivity has a null value in there. But based on your description, that probably should not ever be called.
How are you registering for text messages? If you are using manifest.xml to define the broadcast receivers for text messages, then "Exiting" your app does nothing to prevent those. If you are registering the broadcast receiver programatically, then you will need to unregister at some point. "Exiting" the app does not automatically unregister.
Furthermore, as in other posts you should read up on the application lifecycle. System.exit() is frowned upon, runFinalizerOnExit is deprecated, and onDestroy is not guaranteed to run.
精彩评论