I\'m in the process of trying to make a release build of my first android app to send to a few testers. However, I ran into a problem with it. When you exit the app and then
Another strange cause, restart occurs only when app was launched by clicking on "OPEN" after Copy-to-Device-&-Install.
Test on OS8.1, no launchMode in activity.
I see this issue on Android TV in 2019. Is there a better fix for it? other than
if (!isTaskRoot()) {
finish();
}
It works but looks like a hack more than the actual solution.
Try using android:alwaysRetainTaskState
as shown in the following example:
<activity
android:name="com.jsnider.timelineplanner.MainActivity"
android:alwaysRetainTaskState="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So far I've found out that it's an issue based on how you install it in your real device, specifically:
If you install it using one of the following options, This issue does not appear:
Go to sdk/tools/ using a terminal or command prompt then type
adb install <FILE PATH OF .APK FILE>
In Linux, type:
./adb install <FILE PATH OF .APK FILE>
Simply run your project from Eclipse.
I would be pleased to know if there's any possible way to distribute correct APKs for beta testing. I already tried exporting a signed APK because when you copy and paste an APK and install it manually it shows the rogue behavior.
Update:
I found out a solution. Follow these two Steps:
android:launchMode="singleTask" = true
for all activities of your app in the AndroidMainifest.xml inside the activity tag.Put this code in your Launcher Activity's onCreate()
.
if (!isTaskRoot())
{
final Intent intent = getIntent();
final String intentAction = intent.getAction();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && intentAction != null && intentAction.equals(Intent.ACTION_MAIN)) {
finish();
return;
}
}
This behavior is a bug in Android. Not a special case.
It is the default behavior in Android. For the debug builds it works differently for some reason. It can be solved by adding android:launchMode="singleInstance"
to the activity, you want to restart after you launch from the icon.
When you press the back button in Android, the onDestroy
method is invoked (as opposed to pressing the home button, where only the onPause()
method is invoked).
If you need your app to continue where it left off, save the state of the app in your onDestroy()
method and load that state in the onCreate()
method.