退出整个应用程序一次 [英] exit entire app at once

查看:214
本文介绍了退出整个应用程序一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了code从的此处在我的应用程序,当我点击取消选项,应用程序只是最小化,当我长preSS按住Home键并选择app.It显示同一画面不闪屏或应用程序启动的常见方式 - 因此我假设它只是带我到主屏幕。我在寻找一种方法,我可以完全关闭的主要活动。

我曾尝试以下方法和坠毁每次:

  1. 结束();
  2. mainactivity.class.finish();
  3. 在打开的意图有 systemexit()
  4. 的setResult()在另一个活动。
解决方案

不recommened但你仍然可以使用这个。 这种解决方案更好的去的情况下,你需要退出程序。

据我最好的解决办法是在你的应用程序中包含完成每一项活动。

步骤1)保持一个静态变量mainactivity说。

 公共静态布尔isQuit = FALSE;
 

在一个按钮的点击事件步骤2)使这个变量设置为true。

  mainactivity.isQuit = TRUE;
   完();
 

第三步),并在你的应用程序的每个活动都有如下onrestart方法。

  @覆盖
      保护无效onRestart(){
         // TODO自动生成方法存根
         super.onRestart();
        如果(mainactivity.isQuit)
            完();
    }
 

I have used the code from here in my app, when I click on 'Cancel' option ,the app just minimizes ,when I long press and hold Home button and select the app.It shows the same screen not the splashscreen or the usual way the app starts - So I am assuming it just takes me to home screen. I am looking for a way I can close the main activity completely.

I have tried the following methods and it crashed every time:

  1. finish();
  2. mainactivity.class.finish();
  3. opening an intent which has systemexit()
  4. setresult() in the another activity.

解决方案

Not recommened but still you can use this. Better go with this solution in case you need to quit the app.

According to me the best solution is finish every activity in your app like below.

step1) maintain a static variable in mainactivity say.

  public static boolean isQuit = false;

step2) on click event of an button make this variable to true.

   mainactivity.isQuit = true;
   finish();

step3) And in every activity of your application have onrestart method as below..

  @Override
      protected void onRestart() {
         // TODO Auto-generated method stub
         super.onRestart();
        if(mainactivity.isQuit)
            finish();
    }

这篇关于退出整个应用程序一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆