15

I'm having a very confusing issue. I have built a final release APK of my app, submitted it to the Play Store, and installed on my test device. The application has exhibits different launch mode behavior when I install it this way.

My generated APK is the product of a Gradle build going though both Proguard and zipalign. For ease of explanation, say my app is a dashboard type app whose main Activity shows a launch button for activity B. I took this release APK and installed it to my device via USB 'adb install ' so I'm comparing the exact same APK with two different methods of install.

USB Method: When a user clicks on the button in the main activity to launch Activity B, Activity B is launched and shows on screen. If the user hits the home button (gets a call etc) then comes back to the app, Activity B is still showing. This is the desired (AND EXPECTED) behavior.

Store Method: Downloading the APK from the store and installing/launching again shows the main Activity. When the button is clicked, Activity B is again launched. Now, when the user hits home and comes back, the back stack is apparently cleared and the main Activity is shown again.

I do not specify any special launch modes in the manifest so all activities are standard. How could the method of installation affect such a thing!? This is driving me mad. Does anyone have any idea of why this might be happening?

Andrew G
  • 1,547
  • 1
  • 13
  • 27
  • Just a guess, but are you pushing a release or debug version with adb? – motoku Apr 07 '14 at 22:41
  • release version, same version I am uploading to Play sadly :/ – Andrew G Apr 07 '14 at 22:43
  • OK, have you made sure you are not restoring the application in one instance and not the other? – motoku Apr 07 '14 at 22:53
  • Other than [this](http://stackoverflow.com/questions/14409139/why-does-my-app-size-on-device-differ-than-the-apk-or-play-store-size), I can't find anything saying the functionality of the apk is modified... – motoku Apr 07 '14 at 23:12
  • Yeah this is wacky. No, not restoring or doing anything different in one APK over the other. They are byte by byte identical. The only thing I can think of is to hack in a state machine that manually restores the correct Activity by relaunching but that is ridiculous. – Andrew G Apr 08 '14 at 13:32
  • Have you tried without proguard? – Dumbo Aug 03 '14 at 02:55
  • 1
    possible duplicate of [How can I make an android app stop restarting every time it is opened?](http://stackoverflow.com/questions/13987445/how-can-i-make-an-android-app-stop-restarting-every-time-it-is-opened) – ashiaka Apr 02 '15 at 15:10
  • @AndrewG I am facing the same issue have you find any workaround for that? – Hardik Mehta Sep 11 '17 at 12:46

2 Answers2

-1

I had the same problem and this worked for me. Explicitly set the launchMode in your Manifest's activity element.

android:launchMode="singleTop"

"If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity."

See the documentation for more options and an explanation: http://developer.android.com/guide/topics/manifest/activity-element.html

bornSwift
  • 336
  • 2
  • 8
  • I also facing the same issue to which activity I should apply this launch mode and what should I handle in new intent method – Hardik Mehta Sep 11 '17 at 11:13
-1

The difference is in app priority in the OS. Android will give the app installed from USB a higher priority than play store app, then when the system needs memory it will despose the low and normal priority apps and keeps high priority apps.

Of course this is different from device to another.

user16930239
  • 6,319
  • 2
  • 9
  • 33