Before you tell me that this question has already been asked, let me tell you that none of those questions have an answer that suits me. I have a main Activity for my app. Before it runs, I have a splash screen Activity. If I call finish(), the program returns to my splash screen. I do not want this. Do not tell me to use finish(). I have heard that it is bad practice to not let Android close the app on its own. I know what I am doing...probably....
I want to be able to completely close the application from the second activity. Does anyone know of a way I can do this?
You can call System. exit(); to get out of all the acivities.
writeBytes("kill "+ APP_PID + "\n"); os. flush();
If you want app to be stopped immediately then you have to press the Red stop button. Play button will stop the app only after gradle build is finished.
when you want to close your application, you can call
finishAffinity();
or if you want close it in background also you should write,
android:excludeFromRecents="true"
in AndroidManifest :
<activity
android:name="com.smart.remote.main.SplashActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait"
android:excludeFromRecents="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Use finish()
in your splash screen just before you create your second activity
, then use finish()
is the second activity
: that will not bring back the splash screen.
Executing finish()
on the splash activity is one solution, but two alternative methods are:
android:noHistory="true"
in its manifest entry.FLAG_ACTIVITY_CLEAR_TOP
.My preference would be the first, as users are unlikely to want to ever see the splash screen in the history stack (or at all, for that matter, but that's a different discussion).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With