문제

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();
}
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top