简体   繁体   English

如何从android应用程序注销?

[英]How to logout from android application.?

here is my code.but if this runs my app closed from 60seconds.but when i again press app icon.its open as logged.how to close app with logout.?i added these in my service class. 这是我的代码。但是如果运行我的应用程序从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
}

please give me a suggestion.because we need to sign out from app when idle at more time. 请给我一个建议。因为我们需要在更多时间空闲时从应用注销。 thanks all 谢谢大家

now its ok.i tried with activity class instead of service class and i added code to after login screen going page.now its working perrfect for me :-) 现在它的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.

相关问题 如何从Android应用程序访问Oracle数据库。 - How to access Oracle Data Base from Android Application. 如何从本地android闹钟应用程序获取时间。 是否有机会从AlarmClock功能获取时间? - How to get the time from native android alarm clock application. Is there a chance to get the time from AlarmClock function? 如何保存另一个Android应用程序的sqlite db文件? - How to save sqlite db file of another android application.? 部署Java应用程序。 怎么样? - Deploying a Java application. How? libgdx和android应用程序。作为背景的图象 - libgdx and android application. Image as background android应用程序中的java.lang.NullPointerException。 - java.lang.NullPointerException in android application. 如何从在 Android Webview 中运行的网站注销? - How to logout from a website running in an Android Webview? 如何在sqlite中创建一个新的数据库? 我们必须使用sqlite,因为我们正在制作一个android应用程序。 - how to create a new database in sqlite? we have to use sqlite because we are making an android application. 如何将计算机中的MySql数据库连接到android应用程序? - how can i connect the MySql database in my computer to android application.? 我如何在基于Android-Java的应用程序中喜欢DataTable。 - How do I do like DataTable in Android-Java based application.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM