Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从android应用程序注销。?_Java_Android_Session - Fatal编程技术网

Java 如何从android应用程序注销。?

Java 如何从android应用程序注销。?,java,android,session,Java,Android,Session,这是我的代码。但如果从60秒开始运行,我的应用程序将关闭。但当我再次按下应用程序图标时,它将以已登录状态打开。如何通过注销关闭应用程序?我在我的服务类中添加了这些 public class BackgroundService extends Service { private int interval3 = 10; // 10 seconds private Handler mTimer3 = new Handler(); private Runnable mTask3 = new Runna

这是我的代码。但如果从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方法,并在其中一个帐户中注销them@PriyanRockZ我的意思是,当你点击应用程序图标,应用程序显示已签名时,你可能正在某处存储凭据。你可以在60秒后关闭应用程序后删除/清除数据库秒。或者,您也可以在共享首选项中保持登录状态。在onresume中检查首选项,并在需要注销时清除首选项
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
        }
    }