Search code examples
androidandroid-manifestapkadb

Android app acts differently installed from adb vs sdcard


An issue I was having with my app is that it wasn't resuming to the most recent activity. I added

android:alwaysRetainTaskState="true"

to AndroidManifest.xml. It fixed the issue for debug mode but not when I built for release mode. Kinda.

If I install the app via downloading the release APK to the phone's sdcard and installing from there the mentioned bug exists. If I install the exact same APK via adb the bug does not exist. This is true for both pre and post Android 4.0 devices.

Any ideas? Because I'm so lost.


Solution

  • Do you start the app directly from the installer (after installation the installer asks if you want to start the app). If so, this is your problem. There is a nasty, long-standing bug that apps started by the installer are in a strange state. If you then use the HOME button to return to the HOME screen and then return to your app, Android happily launches the root activity of your app again :-(

    For more details on this bug see http://code.google.com/p/android/issues/detail?id=26658 Many people have struggled for days chasing this problem :-( Please star the issue to raise awareness.

    The bug is there on all devices, on all versions of Android (at least up to ICS, haven't tested on JellyBean yet). It all works as it should in the emulator, so you cannot use emulator behaviour as an indication of real device behaviour.

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