3

I'm using the attribute noHistory=true for the activities I don't want to keep in the back stack. It's working fine on Android 2.3.3 but on 4.0.3 there is a weird behaviour. When the screen goes to sleep and I wake it up, the activity with the noHistory=true is gone!

What's going on here? Is the activity finished when the screen wakes up? Am I using noHistory the wrong way?

Brice Durand
  • 551
  • 5
  • 7

2 Answers2

2

I was just having the same problem today, and I found the solution here :

Android: how to return to Activity with "noHistory" attribute after onStop?

In fact, with noHistory set to true, when the screen goes to sleep, your activity is removed from the stack, and it is not restored when the screen wakes up.

I removed noHistory=true from the layout xml file, and just called finish() when my activity calls another one :

Intent intent = new Intent();
intent.setClass(this, MainActivity.class);
this.startActivity(intent);
finish();

That made the trick ! The previous activity does not appear when I click on the back button.

I am not sure about whether the issue happened on Android 2.x, but what i am sure about is that is working perfectly now on both Android v2.x and Android v4.x

Community
  • 1
  • 1
Yves Delerm
  • 785
  • 4
  • 10
  • That's what I ended up doing. I still don't understand this behaviour on 4.x. There is no reason to remove the activity from the stack when the screen goes to sleep.. – Brice Durand Apr 15 '12 at 08:55
  • When the screen gets off, the activity is paused. What I have observed under Android 4.x is that quickly after, the system asks for the activity to be finished (the onDestroy() method is called). As soon as the activity is finished, Android removes it from the stack. – Yves Delerm Apr 15 '12 at 12:08
  • My previous comment was incomplete : When the screen gets off, the activity is paused. What I have observed under Android 4.x is that quickly after it, the system asks for the activity to be finished (the onDestroy() method is called). As soon as the activity is finished, Android removes it from the stack, that point is normal. So the question is : why is the activity destroyed ? In my opinion, Android 4.x is more "aggressive" about paused activities, and kills them quickly to recover memory. – Yves Delerm Apr 15 '12 at 12:17
0

May have something to do with the fact that onPause() is called when the screen goes to sleep.

vt.
  • 436
  • 6
  • 12