Reputation: 1891
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 ?
Upvotes: 0
Views: 856
Reputation: 6126
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.
Upvotes: 1
Reputation: 77752
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
Upvotes: 3