Obsolete
Status Update
Comments
do...@gmail.com <do...@gmail.com> #2
wow this is stupid. I was going crazy over this as my Launcher activity was always on top as i deploy and install the app directly from the installer. As soon as i opened the app by selecting it from the list of available applications it works. Thanks, i just wasted 4 hours of my life :)
+1
+1
an...@gmail.com <an...@gmail.com> #3
I posted a bug report a few days ago that I thought was specific to tabHost. Then after almost giving up, I tried an insanely simple app where one simple activity navigated to another. I built an .apk (because I knew the issue didn't occur when I was debugging the app on the phone via Eclipse and I couldn't replicate it in the emulator, either) and sure enough the app wasn't resuming on the second activity when I pressed the home key from the 2nd activity. And now I come to learn that it's because I clicked "Open" instead of "Done" in my sideloader? This is probably just a few lines of code for Google to make a permanent fix, and in the meantime virtually every app on the Marketplace has a potential to be broken by something so silly. This bums me out because I spent literally 5 full days of work trying to "fix" a ghost.
[Deleted User] <[Deleted User]> #4
The fact that this bug still exists in Android 4 contributes to my desire to not do any more work on Android. Why is this not fixed? It has existed since API level 1. It effects everyone who develops for Android.
mi...@gmail.com <mi...@gmail.com> #5
Has there been any more discussion about fixing this defect? It's absurd to have to hack around this issue, an issue that I'm seeing in many apps downloaded from that market.
te...@gmail.com <te...@gmail.com> #6
same problem here, wasted 2 sleepless nights already. Should be fixed
we...@gmail.com <we...@gmail.com> #7
I sure hope this is fixed soon. I too ran into it.
js...@gmail.com <js...@gmail.com> #8
+1 this cost us many hours of pain too.
ja...@gmail.com <ja...@gmail.com> #9
This is also affecting my apps. Currently trying to come up with a workaround and/or testing some of the ones suggested on Stack Overflow.
A fix would be nice, but given that the problem presents in every OS version up to 4.0 it's going to have to be "worked around" for the foreseeable future.
A fix would be nice, but given that the problem presents in every OS version up to 4.0 it's going to have to be "worked around" for the foreseeable future.
nm...@gmail.com <nm...@gmail.com> #10
This is also costing us many hours of pain. I chime in here because the description did not include the scenario where the application is installed from the apk attachement feature in gmail. If our app is installed from gmail and then launched from the installation-provided "Open" button, then we have the bad behavior where stack is not saved in the Task. If instead the user clicks the "Done" button provided by the installer, and then launches the application from the application's shortcut then behavior is correct and the correct Activity will be resumed after pressing Home and then revisiting via the application's shortcut (or returning via Task Manager).
th...@gmail.com <th...@gmail.com> #12
Is there any solution yet.
su...@gmail.com <su...@gmail.com> #14
[Comment deleted]
su...@gmail.com <su...@gmail.com> #15
i have just solved this problem.
I have added a code in my first activity(android.intent.category.LAUNCHER)
if (!isTaskRoot()) {
finish();
return;
}
I have added a code in my first activity(android.intent.category.LAUNCHER)
if (!isTaskRoot()) {
finish();
return;
}
ne...@gmail.com <ne...@gmail.com> #16
so what we have to do to fix it ?
[Deleted User] <[Deleted User]> #17
@#16: if you mean the fix on the caller side then the proper fix would be:
The start intent (Intent.ACTION_MAIN) should have proper category (Intent.CATEGORY_LAUNCHER) as well as the proper intent flags (the same ones as the platform launcher uses) Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.
If you meant how could the issue being worked around then previous posts give you details how you can do that.
The start intent (Intent.ACTION_MAIN) should have proper category (Intent.CATEGORY_LAUNCHER) as well as the proper intent flags (the same ones as the platform launcher uses) Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED.
If you meant how could the issue being worked around then previous posts give you details how you can do that.
em...@gmail.com <em...@gmail.com> #18
@#14 Very nice, thank you~
s....@gmail.com <s....@gmail.com> #19
Cool #14, Solved the issue forus. It also worked here. Thanks.
ha...@dianping.com <ha...@dianping.com> #20
[Comment deleted]
ha...@gmail.com <ha...@gmail.com> #21
@#14 thanks your code
aw...@gmail.com <aw...@gmail.com> #22
Suffering from this issue on Android 5.0, too. Please fix this!
en...@google.com <en...@google.com>
la...@gmail.com <la...@gmail.com> #23
[Comment deleted]
la...@gmail.com <la...@gmail.com> #24
@#14 Very nice, thank you~ Its work perfectly.
I am putted this code in my onCreate() method.
e.g
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!isTaskRoot()) {
finish();
return;
}
}
'isTaskRoot()' is member method of Activty class, so do not panic just put this code and enjoy "Happy Coding"
Very disappointed, why android team still not closing this bug ?
I am putted this code in my onCreate() method.
e.g
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(!isTaskRoot()) {
finish();
return;
}
}
'isTaskRoot()' is member method of Activty class, so do not panic just put this code and enjoy "Happy Coding"
Very disappointed, why android team still not closing this bug ?
cv...@gmail.com <cv...@gmail.com> #25
This issue exists in Android 5.1 (facepalm)
sa...@gmail.com <sa...@gmail.com> #27
the original title was accurate!
ti...@gmail.com <ti...@gmail.com> #28
@#14 Thank you very much.
bo...@gmail.com <bo...@gmail.com> #29
For people still getting this in 2015!
You almost realize there are flags for controlling how any activity is launched when you create the intent for that activity?
You are going about solving your problems the wrong way. In fact the other way around.
I think it's one of the philosophies of android to NOT DESTROY activities unless really required (resource constrains)
And you have to make that assumption yourself!
For example:
When first opening the app never aim at the SignInActivity of your app!! Aim at MainActivity (Overview, Dashbord whatever you guys call it). If that activity does not find the user logged in (i.e in your datamodel the user is null) the that activity throws you back to the SignInActivity to get you signed in. And the same is for every scenario involving any data in your CENTRALIZED DATA MODEL.
Do not rely on the history of navigation of your app. Yes your activities must work correctly every time. Do not test "!isTaskRoot()" think about WHY you feel you have to do this!
You almost realize there are flags for controlling how any activity is launched when you create the intent for that activity?
You are going about solving your problems the wrong way. In fact the other way around.
I think it's one of the philosophies of android to NOT DESTROY activities unless really required (resource constrains)
And you have to make that assumption yourself!
For example:
When first opening the app never aim at the SignInActivity of your app!! Aim at MainActivity (Overview, Dashbord whatever you guys call it). If that activity does not find the user logged in (i.e in your datamodel the user is null) the that activity throws you back to the SignInActivity to get you signed in. And the same is for every scenario involving any data in your CENTRALIZED DATA MODEL.
Do not rely on the history of navigation of your app. Yes your activities must work correctly every time. Do not test "!isTaskRoot()" think about WHY you feel you have to do this!
[Deleted User] <[Deleted User]> #30
Bogdan I think you misunderstand.
MainActivity -> SubActivity -> MainActivity is a silly stack to end up with and that's what this is about.
MainActivity -> SubActivity -> MainActivity is a silly stack to end up with and that's what this is about.
dw...@sharpmind.de <dw...@sharpmind.de> #31
Bogdan this is an real Android bug. In certain circumstances the Android framework is creating another instance of the Activity when it shouldn't. This problem is real and has existed for a very long time. There are no flags you can use to fix it. Using isTaskRoot() is just a workaround to detect when the problem happens so that your app can do something intelligent.
This isn't a problem of "bad navigation" or "not understanding the navigation". It is a real, honest to goodness, nasty Android bug.
This isn't a problem of "bad navigation" or "not understanding the navigation". It is a real, honest to goodness, nasty Android bug.
bo...@gmail.com <bo...@gmail.com> #32
Ok DW i'm sorry!
I'm guesing you tried
<activity
android:launchMode="singleTask">
Does this solve the problem without getting you into trouble elsewere?
I'm guesing you tried
<activity
android:launchMode="singleTask">
Does this solve the problem without getting you into trouble elsewere?
dw...@sharpmind.de <dw...@sharpmind.de> #33
Bogdan - No. As I said, this is a bug in Android. Setting launch mode to singleTask or singleInstance does not help. Android STILL creates another instance of the Activity even though it isn't supposed to. It is a bug in the platform!
ma...@gmail.com <ma...@gmail.com> #34
Confirming to be still occurring. Just happened to me. Spent several hours trying to debug our app, but turns out it is on Android level...
pa...@gmail.com <pa...@gmail.com> #35
Still occurs with all "launchMode" options.
al...@gmail.com <al...@gmail.com> #36
I've had the same issue for long time and in my case there was a launchMode="singleInstance" in my LauncherActivity. Removing that fixed the issue. I'm not sure why android forces to recreate your launcher activity if it has singleInstance launch mode, but it works.
Off course you have to finish you launcher activity when you're going to MainActivity and use intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
I also use singleTop in my MainActivity as launchMode.
Off course you have to finish you launcher activity when you're going to MainActivity and use intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
I also use singleTop in my MainActivity as launchMode.
qi...@gmail.com <qi...@gmail.com> #37
isRootTask() doesn't work on some devices
[Deleted User] <[Deleted User]> #38
Still exist in 2017
k....@gmail.com <k....@gmail.com> #39
Still getting the issue
dw...@sharpmind.de <dw...@sharpmind.de> #40
Still broken in Android 7 :-(
dw...@sharpmind.de <dw...@sharpmind.de> #41
Since this bug is marked "obsolete", I created a new issue 64108432 which hopefully will get more attention.
li...@gmail.com <li...@gmail.com> #42
Still not fixed by official,
but fix in huawei p8 android 7.0.
I believe these android philosophies are false
but fix in huawei p8 android 7.0.
I believe these android philosophies are false
me...@gmail.com <me...@gmail.com> #43
Still getting this issue in 2018.
Also, can not reproduce with Min SDK 21.
Also, can not reproduce with Min SDK 21.
[Deleted User] <[Deleted User]> #44
Unfortunately this issue and the related issue
To best illustrate the problem, we've published the following sample project:
The app can also be found on Google Play:
The behavior can be observed in this YouTube video:
[Deleted User] <[Deleted User]> #45
in...@bigredzebra.com <in...@bigredzebra.com> #46
I already opened a new issue for this problem (which has still not been resolved, but is still open) here: https://issuetracker.google.com/issues/64108432
pl...@gmail.com <pl...@gmail.com> #47
I have been hunting for days of a solution for pre-Lollipop (Lollipop + if (!isTaskRoot) works fine. Only alternative was to ask for access permissions which we don't want/need and is not best option & looks overreaching in store listing.
I found this works across devices and does not require and special/particular permissions.
Cannot take any credit just Googled & submitted questions until I found the link below.
https://stackoverflow.com/questions/31156313/activitymanager-getrunningtasks-is-deprecated-android/35423996#35423996
I found this works across devices and does not require and special/particular permissions.
Cannot take any credit just Googled & submitted questions until I found the link below.
dw...@sharpmind.de <dw...@sharpmind.de> #48
I don't understand the previous comment comment #47 ). The "isTaskRoot()" solution works fine on all versions of Android, also pre-Lollipop. What problem are you having on pre-Lollipop devices?
ma...@gmail.com <ma...@gmail.com> #49
Consider following situation when we use Android TV and our app is launcher one:
1) Open 3rd party App, for example Youtube and keep it opened while executing step 2
2) Run App from android studio and wait for it to be opened.
3) Open Youtube or some other 3rd party app again
4) Now press Home
What happens is that part of the code that checks isTaskRoot will finish/destroy that new instance of the MainActivity, but we will be basically locked on Youtube app. We can't go back to our app on home click because our app tries to be started in new task that comes above Youtube task. So we have
Task 1 => MainActivity
Task 2 => MainActivity of Youtube app
Task 3 => MainActivity that will be destroyed because of isTaskRoot check
When MainActivity of Task 3 gets destroyed, Task 2 will be top task with Youtube app activity, so we can't go to original Task 1 on home click.
[Deleted User] <[Deleted User]> #50
How the production apps are doing it? I have never seen Instagram behave like that, or Facebook, or What's App. So there should be a way to fix that issue or at least to use a good workaround. I have followed some workarounds that use isTaskRoot check (it will sometimes kill the activity if it is initial launch or very first launch) or changing the launch mode to other options but it still fails sometimes.
It may close the app upon pressing app icon with the very first launch, but then never happen again after second launch.
If there are professional android devs here, please share the solution, I dont think that the solution is a saint secrete to hide it, I just personally dont know it.
It may close the app upon pressing app icon with the very first launch, but then never happen again after second launch.
If there are professional android devs here, please share the solution, I dont think that the solution is a saint secrete to hide it, I just personally dont know it.
Description
If, after the app is launched, the user presses the HOME key to return to the home screen and then tries to return to the app by selecting it from the list of applications (or by putting a shortcut on the home screen and then selecting the shortcut), the OS launches the root activity of the app AGAIN, bringing the existing task to the foreground and placing ANOTHER instance of the root activity on top of the existing activity stack.
This is fundamentally broken as this is very different from the behaviour if the user initially launched the app by selecting it from the list of available applications. In that case, when the user presses the HOME key and then tries to return to the application by selecting it from the list of applications (or selecting the shortcut),
the OS simply brings the existing task to the foreground. It does NOT create another instance of the root activity.
This behaviour is extremely difficult to debug and has certainly caused countless hours of head-scratching by developers.
This issue was originally reported 3 years ago (by someone else) as
It isn't a problem only for developers. It occurs on real devices running all versions of Android OS, even Android 4.0! We've seen this on HTC Desire running 2.2, HTC Desire S running 2.3, HTC sensation running 4.0 and others.
We've created a sample application that can be used to demonstrate the behaviour. Here is an explanation and step-by-step instructions:
ActivityA is the starting activity. It has a button that will launch
ActivityB and it finishes itself after that launch. This means that if you press the BACK key in ActivityB the home screen will be displayed.
Both activities have a TextView that indicates whether the app is before or after the update of the application.
There are 2 APKs provided: "before.apk" and "after.apk". They both contain exactly the same code, only the version number in the manifest has been changed (this is so we can simulate the "update" from the market).
In order to explain it more clearly, read the following step-by-step instructions. The source code of the sample app, the apk files, the logs and some screenshots can be found in the attached zip file.
00. Preconditions:
Have the "before.apk" installed on your device and the "after.apk" present somewhere on the device's file system (SD-card or whatever).
01. Start the app by using the respective icon.
02. ActivityA is displayed. Press button "launch AcitivtyB" in ActivityA.
03. ActivityB is displayed. Press HOME key. Open any file manager application and click on the "after.apk" and install it. This means
that "before.apk" will be replaced with "after.apk".
04. Once the installation is complete, press the "Open" button in the installer (see 03.png).
05. ActivityA is displayed. Press button "launch ActivityB".
06. ActivityB is displayed. Press HOME key in ActivityB.
07. Launch the application again by using the respective icon.
08. ActivityA is displayed. Notice that in the dumpsys (07.txt) you can see that both ActivityA and ActivityB are active but this shouldn't be the case because ActivityB should only be active after ActivityA has been finished.
Press button "launch ActivityB".
09. ActivityB is displayed. Notice that in the dumpsys (08.txt) you can see that two instances of ActivityB are active.
Press BACK key in ActivityB.
09. ActivityB is displayed. Notice that in the dumpsys (09.txt) you can see that one instance of ActivityB is active.
Press BACK key in ActivityB.
10. The home screen is displayed. Notice that in the dumpsys (10.txt)
you can see that no instance of ActivityA or ActivityB is active anymore.