haawa
haawa

Reputation: 3104

Android application working with locked screen

For example I have an app that counts how many time Camera button was pressed. After locking the screen the app is not working, so is there any way to keep counting presses when screen is locked?

Upvotes: 2

Views: 10042

Answers (2)

Campino
Campino

Reputation: 862

It worked for me:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

I took that from Avoiding resuming app at lock screen

Upvotes: 2

UdayaLakmal
UdayaLakmal

Reputation: 4223

Running Apps and services are pause when the phone is locked, but you can acquire WAKE_LOCK key and do your task

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyWakeLock"); 
wakeLock.acquire();

this will hold the CPU open even if the screen off

Upvotes: 3

Related Questions