In my application I have an “Application” and several Activities. I would like to kill my application after a specific time (ex. 3 minutes) after user pressed the Home button. I’m able to finish the “Application”s process but as long as my activities are alive, they tries to start from their last state.
Thread isOnDisplayThread = new Thread(new Runnable() {
@Override
public void run() {
Timer mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
Log.d(TAG, (isApplicationOnDisplay) ? "Application on display" : "APPLICATION ON BACKGROUND");
if (!isApplicationOnDisplay) {
notOnDisplayTime++;
if (notOnDisplayTime >= 10) {
Process.killProcess(Process.myPid());
}
} else {
notOnDisplayTime = 0;
}
}
}, 0, 1000);
}
});
isOnDisplayThread.run();
P.S. isApplicationOnDisplay is a static boolean controlled by every Activity’s onPause() and onResume() methods.
Is there any way to kill all related activities of an application?
(I can’t understand why everybody tries to kill his own application…)
Killing an application should never be done by an application (though sometimes an task manager has his advantages).
You have full control about the state handling, you decide if an activity continue with the latest state or not. If you don’t want the current behavior, change it, but don’t try to kill your application.
To make it short: The Android OS decides if an application should be killed/stopped or not
Thats how android is designed and how it should be used…