简体   繁体   English

onBackPressed()但活动完成(),然后是onCreate()和onResume()。 无法退出应用

[英]onBackPressed() but Activity finished(), then onCreate(), onResume(). Cannot exit app

Android 2.3.6 Android 2.3.6
Steps to reproduce. 重现步骤。 Goto activity. 转到活动。
Restart Phone. 重新启动电话。 Click Back Button. 单击后退按钮。 Nothing happens. 什么都没发生。 Actually activity recreated again, then resume called() so cannot exit app. 实际上,活动已重新创建,然后恢复被调用的(),因此无法退出应用程序。 It just stays on. 它一直保持下去。 What could cause this. 是什么原因造成的。 I have selected the app as default app launcher, so maybe this has something to do with it. 我选择了该应用程序作为默认应用程序启动器,所以也许这与它有关。

Question is how can this possibly not close the activity? 问题是这怎么可能无法关闭活动? I'm doing on back pressed, and I'm also doing a finish(). 我正在做背部按压,而且还在做finish()。 I have log statements in onResume(), so I don't think its being restarted. 我在onResume()中有日志语句,因此我认为它不会重新启动。 What is it about restarting the phone that does this. 重新启动执行此操作的手机有什么用。 It works otherwise. 否则它将起作用。

 @Override
 public void onBackPressed() {
        super.onBackPressed();
        finish();


    }
}

UPDATE: What happens is the activity is immediately recreated. 更新:发生的事情是立即重新创建活动。 onCreate(), onResume(). onCreate(),onResume()。 So the activity is stopped, but for some reason it does not leave. 因此该活动已停止,但由于某种原因它没有离开。 Here is activity intent filters in manifest: 这是清单中的活动意图过滤器:

       <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.HOME" />
        </intent-filter>

Is there something about this that keeps me from exiting the app? 有什么可以阻止我退出该应用程序的吗?

Try below code , hope it helps you. 尝试下面的代码,希望对您有所帮助。

ActivityCompat.finishAffinity(Youractivity.this);
finish();

Please try below code hope it will work for you 请尝试以下代码,希望它对您有用

/**
     * This method is use to handle back key event
     */
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            finish();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 活动可以在 onCreate() 完成之前处理 onBackPressed() 吗? - Can an activity handle onBackPressed() before onCreate() is finished? 未调用活动onCreate和onResume - Activity onCreate and onResume not called 当应用程序将用户引导至活动时调用 onCreate 和 onResume - onCreate and onResume were called when app direct user to an activity Android在onCreate中保存微调器状态,并在onResume中保存活动 - Android Save spinner state in onCreate, and Activity onResume Android Studio活动-使用onCreate(),onResume()等 - Android Studio activity - using onCreate(), onResume() etc 我的活动在 onResume() 之前调用 onCreate() - My activity invokes onCreate() before onResume() 如果应用程序闲置了数小时并被OS破坏,是否在Activity.onResume之前调用Application.onCreate? - Is Application.onCreate called before Activity.onResume if app has been idle for hours and destroyed by OS? 清理堆栈并退出应用程序onBackPressed() - clean stack and exit app onBackPressed() Android 在 onResume() 之后无法调用 onCreate() - Android cannot called onCreate() after onResume() Android:surfaceView无法在onCreate()中获取getHolder(),而必须在onResume()中 - Android : surfaceView cannot getHolder() in onCreate(), must in onResume()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM