Shivaprasad C
Shivaprasad C

Reputation: 165

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...

Upvotes: 10

Views: 3665

Answers (2)

Sobakus
Sobakus

Reputation: 181

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! :/

Upvotes: 15

lesscome
lesscome

Reputation: 64

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>

Upvotes: 4

Related Questions