每次按下主页按钮后运行应用程序时,我的应用程序似乎都会重新启动。该应用程序有一个Timer
需要在按下主页按钮后继续。如果打开,我会覆盖后退按钮以最小化应用程序Timer
,有没有办法使用主页按钮来做到这一点?
我onResume()
现在是这样的:
@Override
public void onResume() {
super.onResume();
}
每次按下主页按钮后运行应用程序时,我的应用程序似乎都会重新启动。该应用程序有一个Timer
需要在按下主页按钮后继续。如果打开,我会覆盖后退按钮以最小化应用程序Timer
,有没有办法使用主页按钮来做到这一点?
我onResume()
现在是这样的:
@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()
.