I click HOME button and the program minimizes; but when I press the app icon, the program is launched twice

2.9k Views Asked by At

I have the following problem:

When I press the Android HOME key, I can see the "Desktop" and my app icon. Then I press my app icon and my application launches twice. I don't want open my app twice.

How my program works:

I have 4 Activities (A, B, C, D).

A - The Main Activity: It is the first to open. It opens the other activity that has a lot of buttons. It's like a Java's main() method. I show a SplashScreen and I call another Activity. Then I finish my activity "A".

B - The Menu Screen: In this activity, I have some buttons, like a menu. I have a configuration button, update button, and Login Button. When I click the login button, I finish this activity and open the Login Screen (Activity "C").

C - The Login Screen: The user writes the Login and Password. If the login is successful, I finish this activity and open the Activity "D".

D - The application main screen: It stays opened all the time and launches another Activities. I finish this when I want close my application.

P.S.: I tried change the launchMode flag (androidManifest.xml), but didn't work.

My AndroidManifest.xml bellow:

<application android:label="@string/app_name" android:icon="@drawable/icon" android:name="MyApplication">
    <activity android:name="A"
              android:label="@string/app_name"
              android:configChanges="orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="br.com.site.B" android:label="@string/app_name" />
    <activity android:name="br.com.site.C" android:label="@string/app_name" />
    <activity android:name="br.com.site.D" android:label="@string/app_name" />
</application>

And this is my Activity "A.java" source:

public class A extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        finish();
        startActivity(new Intent(this, AtualizaDadosFrame.class));
    }
}

I don't want open my app twice.

Thanks in advance!

3

There are 3 best solutions below

0
On

You should set the desired launch mode in your AndroidManifest.xml.

0
On

You can restrict this..... Please go through below link.

Home key press behaviour

1
On

I'm going to assume that you started the app initially (the first time) from an IDE (like Eclipse or IntelliJ). If so, this is a known bug in Android (see http://code.google.com/p/android/issues/detail?id=26658 ). Many people have struggled for days chasing this problem :-(

Please don't change the launchMode. This is not the correct way to solve this problem. The default (standard) launchMode is the one that works in most cases.

EDIT (Added link to workaround):

A simple workaround for this problem can be found at http://code.google.com/p/android/issues/detail?id=2373#c21