3
我希望在特定的時間間隔後關閉後臺應用程序。 基本上我希望保持用戶會話。會話可以持續5到10分鐘。在黑莓中的特定時間間隔後關閉後臺應用程序
我希望在特定的時間間隔後關閉後臺應用程序。 基本上我希望保持用戶會話。會話可以持續5到10分鐘。在黑莓中的特定時間間隔後關閉後臺應用程序
// 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-07 11:52:15
5或10分鐘後使用System.Exit(0); – Signare 2012-08-07 11:46:46