Question

In an Android-app I load an Activity as Intent:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startApp();
    }
    private void startApp() {
        Intent i = new Intent(this, WebViewLoader.class);
        startActivity(i);
    }
}

With this code, a "WakeLock" starts - the app does not go to sleep-mode again. I can see the WakeLock clear with the console-command:

adb shell dump sys power

Dump:

Wake Locks: size=1
  SCREEN_BRIGHT_WAKE_LOCK        'WindowManager' ON_AFTER_RELEASE (uid=1000, pid=386, ws=WorkSource{10085})

Suspend Blockers: size=4
  PowerManagerService.WakeLocks: ref count=1
  PowerManagerService.Display: ref count=1
  PowerManagerService.Broadcasts: ref count=0
  PowerManagerService.WirelessChargerDetector: ref count=0

How can I deactivate this WakeLock?

If I uncomment the line "startActivity(i);" in the code-example above, no WakeLock is given (expected behavior). So somehow the starting of the Activty starts also a WakeLock. By the way: I have no WakeLock feature in the loaded Activity as well. It's basically a WebView-Loader with some async JavaScript-calls...

Was it helpful?

Solution 2

This one helped me: https://stackoverflow.com/a/11759222

I had set a flag in my layout-file by accident: android:keepScreenOn="true". I set it to false and sleep mode is coming back!!

OTHER TIPS

Remove the following permission from the Manifest.xml file...

<uses-permission android:name="android.permission.WAKE_LOCK" /> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top