There is an Activity that starts when the application starts.

<activity android:name=".activity.InitActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 

After the necessary initialization, another MainActivity is started from it. When you click on the "Back" button, InitActivity returns from the back stack, although this should not happen. How to implement a similar functionality?

The search did not answer for my situation. android:noHistory="true" parameter in the manifest is not appropriate, because In InitActivity, a request is made to get a geo-location, and if the GPS module is disabled, a dial-in window is called to turn it on, after it is closed, InitActivity is no longer in the back stack because of this parameter and the application simply exits.

  • Try to finish splash activations before the start of the main activity - YuriySPb

2 answers 2

In the manifest, indicate that MainActivity starts with the following parameters:

 <activity android:name=".MainActivity" android:clearTaskOnLaunch="true" android:launchMode="singleTop"/> 

clearTaskOnLaunch = "true" - so that the task is cleared after launching MainActivity, launchMode = "singleTop" - so that the MainActivity in task is always in only one instance

  • one
    Thank you, the issue is resolved. - Alexander Lomovskiy

Why should this not happen? it is in the order of things. In general, just after launching the MainActivity, terminate InitActivity - InitActivity.this.finish ();

  • This should not happen for my situation, after launching MainActivity I call finish() but this, surprisingly, does not help, when I click "Back" I still return to InitActivity - Alexander Lomovskiy