[英]How to logout from android application.?
这是我的代码。但是如果运行我的应用程序从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
}
请给我一个建议。因为我们需要在更多时间空闲时从应用注销。 谢谢大家
现在它的ok.i尝试使用活动类而不是服务类,并且我在登录屏幕转到page。之后添加了代码。现在它对我来说是完美的:-)
public class #MyActivityClass extends Activity {
//=============================================================================================================================
private Handler mTimer3 = new Handler();
private Runnable mTask3 = new Runnable() {
public void run() {
CountDownTimer timer = new CountDownTimer(10*1000, 1000) {
public void onTick(long millisUntilFinished) {
Log.w("Seconds remaining: ", String.valueOf(millisUntilFinished / 1000));
}
public void onFinish() {
//Here finally added finish(); and System.exit(0); methods
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//***Change Here***
startActivity(intent);
finish();
System.exit(0);
}
};
timer.start();
mTimer3.postDelayed(this, interval3 * 1000L);
}
};
private int interval3 = 10*60; // 60 seconds
@Override
protected void onDestroy() {
if (mTimer3 != null) {
mTimer3.removeCallbacks(mTask3); // cancel the timer
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.