Closing my Android app in my main activity on back pressed

[亡魂溺海] 提交于 2020-01-06 19:59:58

问题


I have two activities:

A: a Splash Screen

B: the Main activity

When the application starts, I show the splash screen with a short video then call B. I want the user to be able to close application with the back button in activity B. (The user shouldn't see splash screen again.)


回答1:


You can set android:noHistory="true" for the splash screen in the manifest. This will not add the activity to the back stack.

<activity
    android:name="SplashScreen"
    android:noHistory="true"
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>



回答2:


In your splash screen call finish() when you start Activity B.



来源:https://stackoverflow.com/questions/10865415/closing-my-android-app-in-my-main-activity-on-back-pressed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!