0

Recently I noticed one thing in my app. I created apk for my app say ABC.apk and copied to my device and installed it by clicking on it. After the installation got successfully completed, I got 2 options 'Done' and 'Open', the usual options we get after installation. I clicked on 'Open' and run the app. I moved to some screen and I minimized the app and moved to someother app, when I click my ABC, it started from my first screen. It was just fraction of seconds I moved back to it, hence it should not be killed though launched it like it is first time.

Few things I noticed I if I explicitly killed this first instance from background running apps and start the app again it is not giving me this problem, same if I click 'Done' instead of 'Open' it works fine.

Is there anyone who are facing same issue, or have some solution for it?

Thanks in advance. Prajakta

  • Try onSavedInstance... I don't think there's any problem with where you clicked Done or Open – suku Jun 30 '16 at 10:16

2 Answers2

1

The problem is the way that the app gets launched from the installer doesn't exactly match the way Android launches apps from the HOME screen. Because this, if you initially launch your app from the installer, when you then later launch the app again from the HOME screen, Android doesn't recognize that the app is already running and just creates a new instance of the root Activity and adds it to the existing task on top of whatever activities are already there.

This is why, if you kill the app and start it again from the HOME screen, you won't ever see this strange behaviour.

This is a nasty Android bug which has been around since the dawn of time and is still broken, even though countless issues have been opened about it and the behaviour is reproducible and well-documented.

See the following issues and questions:

There is a workaround documented in my answer to Re-launch of Activity on Home button, but...only the first time

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

Just some general comments that come to mind that you must consider that can cause problems.

  1. If you are trying to deploy an apk, did you switch from debug to release before building it? Make sure you are doing a full release. Do a clean and rebuild while in release mode as well.
  2. Did you sign the apk?
  3. Make sure all the necessary (if any) permissions are set in the manifest that will be needed by your app, on the device.

Hope these help point you in a direction.

Mike

Michael Bedford
  • 1,742
  • 20
  • 48