I want to count the amount of unlocks, now there are post like this, but they don't explain how to efficiently count unlocks while the app is closed, can I get any code examples? I have tried to use background services, but I don't want a notification constantly displayed while the unlocks are counted.
Asked
Active
Viewed 37 times
1 Answers
0
Register a BroadcastReceiver. The filter you're looking for is ACTION_USER_PRESENT.
In your onReceive()
function is triggered, you can load the current number from SharedPreferences, add one and save it back.

RumburaK
- 1,985
- 1
- 21
- 30
-
no need for services or something like that? – Nikola Đuranović Dec 11 '20 at 18:33
-
1no, I think you don't need an ongoing running process or service, you just need to get triggered, execute your bit of code and exit! – RumburaK Dec 12 '20 at 19:34