【发布时间】:2014-04-16 11:57:49
【问题描述】:
这是我的代码。但是如果这运行我的应用程序从 60 秒关闭。但是当我再次按下应用程序图标时。它以已登录的方式打开。如何通过注销关闭应用程序。?我在我的服务类中添加了这些。
public class BackgroundService extends Service {
private int interval3 = 10; // 10 seconds
private Handler mTimer3 = new Handler();
private Runnable mTask3 = new Runnable() {
public void run() {
mTimer3.postDelayed(this, interval3 * 1000L);
CountDownTimer timer = new CountDownTimer(10*1000, 1000) {
public void onTick(long millisUntilFinished) {
Log.w("Seconds remaining: ", String.valueOf(millisUntilFinished / 1000));
}
public void onFinish() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
};
timer.start();
}
};
public void onCreate() {
mTimer1.postDelayed(mTask1, interval1 * 1000L); // start the timer for the first time
mTimer2.postDelayed(mTask2, interval2 * 1000L); // start the timer for the first time
mTimer3.postDelayed(mTask3, interval3 * 1000L); // start the timer for the first time
}
请给我一个建议。因为我们需要在空闲时退出应用程序。 谢谢大家
【问题讨论】:
-
您将登录凭据存储在哪里?
-
您可能需要覆盖活动中的 onPause 或 onResume 方法并注销其中一个
-
@PriyanRockZ 我的意思是,当您单击应用程序图标并且应用程序显示已签名时,您可能会将凭据存储在某处。
-
应用在 60 秒后关闭后,您可以删除/清除数据库。
-
或者,您也可以在共享首选项中保持登录状态。检查 onresume 中的首选项并在需要注销时清除首选项