How can I disable 'go back' to some activity?

前端 未结 4 1238
感情败类
感情败类 2020-12-23 09:33

I don\'t want the user to be able to go back to the splashscreen of my app. One solution seems to be to check if the activity below the current one is an instance of the spl

相关标签:
4条回答
  • 2020-12-23 10:12

    Call finish() in your Splash Screen activity right after starting the next activity.

    Another approach is to add this attribute to your activity in AndroidManifest.xml: android:noHistory="true"

    Example:

    <activity android:name=".SplashActivity" android:noHistory="true"/>
    

    This attribute instructs Android to remove SplashActivity from the history stack once its navigated away from.

    0 讨论(0)
  • 2020-12-23 10:15

    Just call context.finish() after context.startActivity()

    0 讨论(0)
  • 2020-12-23 10:26

    try the following when calling the next Activity from your Splashscreen:

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    
    0 讨论(0)
  • 2020-12-23 10:28
    <activity android:name=".SplashActivity" android:noHistory="true"/>
    

    From the documentation:

    Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".

    A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it. In this case, onActivityResult() is never called if you start another activity for a result from this activity.

    This attribute was introduced in API Level 3.

    0 讨论(0)
提交回复
热议问题