4

I developed a small android application and recently discovered a strange behavior.

When I navigate to an arbitrary Activity after installing this app using usb and eclipse I can leave the app, go to the android home screen or another application and then return to the mentioned arbitrary Activity directly by "starting" the application again.

But when I install the application on the phone directly by downloading the apk-file, I will always return to the root Activity of the application when I return to this app, after I switched to another application or the android home screen.

Does anybody know where this behavior comes from or how I can fix this issue?

UPDATE: I run the application on real hardware in both cases.

ashiaka
  • 3,994
  • 8
  • 32
  • 45
  • 1
    oops, I think I found a relevant thread/question on stack overflow. I will check it out and delete this question if necessary. –  Dec 21 '12 at 09:30
  • it's not relavant to my topic –  Dec 21 '12 at 10:01

2 Answers2

5

place in your manifest file android:launchMode="standard" for that particular activity for which you want to display only once.

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
  • I don't think this answers the OP's question. It's something entirely different. – Kazekage Gaara Dec 21 '12 at 09:37
  • my first attempt didn't work so far. Do I have to put this attribute in the manifest once for every activity? –  Dec 21 '12 at 10:09
  • If you want the same behavior for every Activity then you should,,,, – Avadhani Y Dec 21 '12 at 10:11
  • With these attributes set I have the same issues regarding the application after installing by USB too. I've put the attribute in every activity tag. –  Dec 21 '12 at 10:21
  • I dont know why u didnt get resolved... While adding the above line only to rootActivity which i suggested will help u in displaying the Arbitrary Activity only when u launch the app other than the first time...rootActivity will be displayed only first time.... do u wish to have the same behavior...??? – Avadhani Y Dec 21 '12 at 10:25
  • Yes I want to return to the last opened Activity always. Currently with the attribute set for every activity or only for the root activity the app starts again at the root activity. –  Dec 21 '12 at 10:34
  • no problem, I couldn't get it working with this attribute either. But I found another way to do it. Thx anyway. –  Dec 21 '12 at 14:03
1

This is because of the way the system handles the application.

It is entirely upto the system to destroy your application upon the needs of other applications.

When you run it on your emulator, it does not destroy your application and hence, you resume from the same Activity you left.

But when you run it on your device, the device might feel that the memory occupied by the application needs to be freed up, and hence destroys the application. And the next time you start, it starts it from the beginning.

Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
  • to avoid misunderstandings: I run the application on real hardware in both cases. –  Dec 21 '12 at 09:42
  • Even then, it's entirely upto the system when to destroy your `Activity`. You cannot predict it. Or maybe I've not understood your question. – Kazekage Gaara Dec 21 '12 at 09:45
  • The difference in behavior I mentioned is totally dependent in the way I install the app in my case. When I download the apk file by browser and install it directly on my phone the app will restart every time I return to it. But when I install the app on the phone by USB and Eclipse I can always return to my last opened activity. –  Dec 21 '12 at 09:49
  • Yes @ashiaka i too faced the same issue just 2 days before when my client posted this as a bug. I found the solution by placing android:launchMode="singleInstance" - This works fine and independent of "From where u have launched the apk by using USB/IDE or browser" in my manifest activity. Please refer this link and you can find the difference between android:launchMode="singleInstance|singleTask|singleTop|standard" : http://developer.android.com/intl/ja/guide/topics/manifest/activity-element.html#lmode – Avadhani Y Dec 21 '12 at 09:56
  • @ashiaka Then there must be some other issue with it. Wait for any other answer. – Kazekage Gaara Dec 21 '12 at 09:57
  • @KazekageGaara Can u pls tell what is the issue with my answer? – Avadhani Y Dec 21 '12 at 10:01
  • @Avadhani Maybe you are right, but I'm unable to link the OP's issue with your answer. That's all. – Kazekage Gaara Dec 21 '12 at 10:17