Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity restarts after Unlocking device

I am creating a simple Android project. But my every activity gets Restart when user unlock the screen(after locking). Is it normal behavior of android app? OR i have to handle it in Manifest? or some where else? Please Help...

like image 516
Shivaprasad C Avatar asked Dec 08 '11 06:12

Shivaprasad C


2 Answers

If your target build version is Honeycomb 3.2 (API Level 13) or higher you must put the screenSize flag too, as in:

<activity
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:name="YOUR ACTIVITY NAME">
</activity>

because even with the "orientation" flag you app will be killed and recreated again with every orientation change when your app is the active one, either being visible on screen or hidden by the lock screen. This is because the usable screen size, mainly in tablets, actually changes due to the change in placement of the system action bar.

This drove me crazy for hours! :/

like image 101
Sobakus Avatar answered Sep 25 '22 07:09

Sobakus


Need to add android:configChanges="orientation|keyboardHidden" in manifest for every Activity. And is resolves the problem

    <activity
        android:configChanges="orientation|keyboardHidden"
        android:name="YOUR ACTIVITY NAME">
    </activity>
like image 41
lesscome Avatar answered Sep 23 '22 07:09

lesscome