3

I am developing an app which records unlocks of mobile. But I am having problem when my app is manually killed i.e. when you remove app from recent apps. How can i record broadcast even when app is killed?

I am using ACTION_USER_PRESENT for recording unlocks.

  • 1
    Seems like currently you are registering your receiver for some activity only, Register it as androidmanifest.xml then you will get even if app is killed. – Rujul Gandhi Jan 22 '20 at 14:44

1 Answers1

3

You'll need to create a Service and inside this service create the broadcast receiver that you need.

This answer Certainly will help you : Implement Broadcast receiver inside a Service

Rodrigo Gontijo
  • 587
  • 1
  • 9
  • 21
  • Sir, do i need to add the service in ANDROID.MANIFEST file –  Jan 22 '20 at 16:05
  • @Dharmik if the answer helped you, please mark it as correct! Thanks man! – Rodrigo Gontijo Jan 22 '20 at 18:34
  • I am running my app in Xiomi Redmi. ACTION_USER_PRESENT in service is not runnning on killing the app. But once I turn off the MIUI optimization in Developer options the app starts working. So my question is that how can do that automatically in app to turn that off in all the mobile? –  Jan 24 '20 at 07:51
  • Android kill some background services in order to save battery. This answer might help you. Please, upvote this as correct, helps a lot! – Rodrigo Gontijo Jan 27 '20 at 13:24