I'm using only an application that uses SMS_Receive Intent Filter and based on receiving an SMS , and it does few calculations , the problem is when going back or home , the application still responds to the incoming SMS which has a special tag and it shows the toasts to the desktop of the android screen , how do I close the application completely ?
-
possible duplicate of [Set BroadcastReceiver to be inactive](http://stackoverflow.com/questions/3096246/set-broadcastreceiver-to-be-inactive) – EboMike Nov 29 '10 at 06:00
2 Answers
You don't close an Android application. Leave that to the operating system. Processes stay active (although dormant) until the OS decides it needs more resources. Please don't try to outsmart that. Some apps do, and they suck.
I don't understand what you mean with "the application still responds to the incoming SMS" - do you have a broadcast receiver? If so, the receiver is always active. This is by design. If you don't want it to run, store a flag somewhere (SharedPreferences
, for example) and set that to false whenever you want the broadcast receiver to ignore a broadcast.
EDIT: This is actually a dupe. Check this answer for a more elegant solution: Set BroadcastReceiver to be inactive
-
Yes, I'm using a brodcast receiver , how do I close it on application exit ? – andre_lamothe Nov 29 '10 at 05:58
-
Yeah @Ahmed do understand that by pressing HOME you do not close an app you just minimize it.App will be alive then until you press BACK. – 100rabh Nov 29 '10 at 05:58
-
Yes , when I do press back , the application's broadcast receiver is still active, how do I close it ? – andre_lamothe Nov 29 '10 at 06:00
-
You don't close it! Like I said, if you want to disable it, you could set a boolean SharedPreference that your broadcast receiver will check. Or, here is an even more elegant approach: http://stackoverflow.com/questions/3096246/set-broadcastreceiver-to-be-inactive – EboMike Nov 29 '10 at 06:00
Another approach is to register your BroadcastReceiver in your activity's OnStart or OnResume method using registerReceiver and unregister it in OnStop or OnPause using unregisterReceiver. You would do this instead of declaring the BroadcastReceiver in your manifest.
This way when press back, the broadcast receiver would be unregistered when the activity is not visible.

- 6,106
- 37
- 35
-
I wonder though - wouldn't the receiver be active when you first reboot your phone? (Unless you tag it with `android:enabled="false"` in the manifest file) – EboMike Nov 29 '10 at 16:30
-
No, I'm talking about not registering the receiver in the manifest at all and doing it all in code. – dhaag23 Nov 29 '10 at 19:49