一定時間後にバックグラウンドでアプリケーションを閉じたい。基本的にはユーザー セッションを維持したいと考えています。セッションは最大 5 ~ 10 分続く場合があります。
質問する
293 次
1 に答える
6
// to close the application after some time if it is in background.
// you have to override the following method. Pass the time in seconds
// after which you want to close the application.
public void deactivate(){
new CloseAppInBackground(time duration);
}
public class CloseAppInBackground {
Timer timer;
public CloseAppInBackground(int seconds) {
timer = new Timer();
timer.schedule(new CloseBackgroundAppTask(), seconds*1000);
}
class CloseBackgroundAppTask extends TimerTask {
public void run() {
// check whether the application is in foreground or not
if(!UiApplication.getUiApplication().isForeground())
System.exit(0); // exit the application.
timer.cancel(); //Terminate the timer thread
}
}
}
于 2012-08-07T11:47:25.560 に答える