Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistency with noHistory attribute in Android 4.0.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?

like image 890
Brice Durand Avatar asked Feb 01 '26 16:02

Brice Durand


1 Answers

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

like image 65
Yves Delerm Avatar answered Feb 03 '26 05:02

Yves Delerm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!