Francesco Francesco - 5 months ago 34
Android Question

Android activity closes two times

i have an android app and it works pretty well but just recently it started to show a problem.
The problem is that it starts normally but when i click back it creates a new main activity and when i click back another time the application closes correctly .

Here there's a video of that:

I can't get ahead of this problem by myself so does anyone knows why it happens?

The activity is launched with this code.

mHandler = new Handler();
mActivityLaunchRunnable = new Runnable() {
public void run() {
// This method will be executed once the timer is over
// Start app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
// close this activity
mHandler.postDelayed(mActivityLaunchRunnable, SPLASH_TIME_OUT);
initialTime = System.currentTimeMillis();

And the onBackPressed is not overridden

Answer Source

you need to stop adding the splash screen activity to the stack. you can do this this like below in your manifest:

android:noHistory="true" />

then you can remove finish() in your code snippet.

note: another way to do this is to use FLAG_ACTIVITY_NO_HISTORY

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download