0

In our AndroidManifest.xml, we added android:launchMode="singleInstance" to avoid multiple instances running at the same time.

However, the App now runs in 2 instances at the same time.

This issue only appears when we installed via APK using signed production keystore; when we run in Eclipse, the same issue does not happen at all.

Where else I overlooked ?

p.s. we tried singleTop and singleTask too.


Update: When I click App Icon, it runs. Then, click Home button, it runs again (starts from beginning).

Raptor
  • 53,206
  • 45
  • 230
  • 366
  • Can you explain more detail your problem with multiple instances (how do you know that)? Does it starting again by press home button? As it seem looks like my previous problem – ductran Aug 07 '14 at 07:03
  • Updated the question; yes, exactly the same as your problem – Raptor Aug 07 '14 at 07:14

2 Answers2

1

here is your answer. It is long-standing nasty Android bug .This bug happened when your app is launched from other apps (for example, opening from apk installer)

Your problem can be solved by detect when Android has launched a second instance of your root activity into an existing task.
Try this one on your first activity's onCreate:

 if(!isTaskRoot()) {
   finish();
    return;
 }
Community
  • 1
  • 1
ductran
  • 10,043
  • 19
  • 82
  • 165
0

I believe you need to put

<activity android:launchMode="singleInstance" /activity>

in the manifest file.

  • Add an additiona activity launching flag: FLAG_ACTIVITY_SINGLE_TOP, in order to make it always on top of the screen. data.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); –  Aug 07 '14 at 06:40