Question

My App seems to restart everytime the App is Run after the Home button is pressed. The App has a Timer which needs to continue once the Home button is pressed. I override the Back button to minimize the app if the Timer is on, is there a way to do this with the Home button?

My onResume() is this at the moment:

@Override
public void onResume() {
    super.onResume();
}
Was it helpful?

Solution

The App has a Timer() which needs to continue once the Home button is pressed.

I suggest a different approach: log the time the Timer started and simply recreate the Timer in onResume(). This way you don't have to worry about the app being killed, running the Timer in a service, etc. If you want a task to be run while the app is paused, setup a AlarmManager event in onPause().


I override the Back button to Minimise the app if the Timer() is on, is there a way to do this with the Home button?

To address this specifically, you can use onUserLeaveHint() or the generalized onPause().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top