0

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();
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
KickAss
  • 4,210
  • 8
  • 33
  • 41

1 Answers1

1

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().

Sam
  • 86,580
  • 20
  • 181
  • 179