When my application is idle, Android kills the process. If user reopens the application after some time, only the top Activity is created - this is a problem for me because the activity depends on initialization of other objects (which are now destroyed).
What I want to do in that case is to re-launch the application. How can I do that?
Reboot Manager / Widget is a combination widget and application for Android devices. It lets you schedule a fast reboot, full boot, hot reboot, recovery or full shutdown via a simple graphical user interface. You can also set up nightly reboots of your smartphone or tablet.
First, the easiest way to do what you're trying to do is to launch an Android Broadcast when the app is killed manually, and define a custom BroadcastReceiver to trigger a service restart after that. Dear Dr Sabri Allani, If your Service is started by your app then actually your service is running on main process.
In order to restart your application when it crashed you should do the following : In the onCreate method, in your main activity initialize a PendingIntent member: Intent intent = PendingIntent. getActivity( YourApplication.
Android app doesn't call "onDestroy()" when killed (ICS)
Just identify that your Application
is being launched after it was previously destroyed by Android, you could do this by keeping a variable in a custom Application
class, and set it to true
after your applicaiton is initialized. So when the applicaction is re-launched, this flag is false, and then just make an Intent
to launch your main Activity
specifying FLAG_ACTIVITY_CLEAR_TOP
:
Intent reLaunchMain=new Intent(this,MainActivity.class);
reLaunchMain.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(reLaunchMain);
I think this answer only for you.
After finish progress call this
finish();
Intent intent = new Intent(this, sameactivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With