Reputation: 348
I want to know what exactly happens when app is Settings->Manage Applications->force closed. Does it calls onDestroy().I want to restart my app if it is force closed by user. How to do this. I was wondering if I can rertart it on receving SMS or call using broadcastReceivers.
Yup I am doing the same thing. I am checking ic my service is running using this code, but it always display "service running" Toast
boolean isServiceRunning = AppSettings.getServiceRunning(context);
if (isServiceRunning)
{
Toast.makeText(context,"service running", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context,"service stopped", Toast.LENGTH_LONG).show();
}
I am writing this in onReceive() of broadcastReceiver
Please help me with this.
Upvotes: 0
Views: 275
Reputation: 545
Restarting an app after user force closed it might be considered as a sign of malware. It's highly discouraged. Having said that, if you really want to restart it back on, use AlarmManager and check for app status every hour or so.
Instead of SMS or phone call, it might be a better idea to catch android.intent.action.SCREEN_ON
Intent and restart your application.
Upvotes: 0
Reputation: 3084
Force close is:
android.os.Process.killProcess(android.os.Process.myPid());
Register your receiver in the AndroidManifest. That way it will be called even when your app is not running: R.styleable.AndroidManifestReceiver
You could then check in the BroadcastReceiver whether the service is still running and restart it.
See for example the class SmSForwarder here. The broadcastreceiver does not need to run because it is registerend in the AndroidManifest.xml (see line 29). Android will start the Broadcastreceiver as soon as the Intent "android.provider.Telephony.SMS_RECEIVED" is sent.
Upvotes: 0