0

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!

eliangela
  • 253
  • 2
  • 5
  • 21
  • What do you mean open your app twice? you don't want to see activities a-c again? – FoamyGuy May 22 '12 at 15:36
  • Did you launch your app initially (the first time) via an IDE (like Eclipse or IntelliJ)? How did you install the app on the phone? – David Wasser May 22 '12 at 15:55
  • Hi, David Wasser! The application is installed on the phone. By the way, this error occurs only on the phone. – eliangela May 22 '12 at 19:40
  • OK, How did you install the application on the phone and how do you start the application the **first time**? – David Wasser May 23 '12 at 06:59
  • Hi, David! I copied the APK file to the phone, and I installed clicking on the APK file. After the application is installed, I click on the app icon to start it. – eliangela May 23 '12 at 12:17

3 Answers3

2

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

David Wasser
  • 93,459
  • 16
  • 209
  • 274
0

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

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
0

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

Home key press behaviour

Community
  • 1
  • 1
Bhaskar Reddy
  • 480
  • 5
  • 13