0

I want to open an activity in android as soon as either charger connects or disconnects. I have used a Broadcast Receiver which is working well.

Please tell me can i launch an activity directly from Broadcast Receiver, how? OR I have to implement a service which is looking after the charging state and opens an activity as soon as the charger state changes. Please guide me.

Thanks in advance.

a_local_nobody
  • 7,360
  • 5
  • 25
  • 45
  • There are plenty of answers on Stackoverflow about how to launch an `Activity` from a `BroadcastReceiver`. However, you shouldn't do this and Android has added a number of measures to prevent activities from being launched by background components (`Service` or `BroadcastReceiver`) as this is considered "annoying" to the user. Normally you would just show a `Notification` and allow the user to decide when to open the `Activity`. See https://developer.android.com/guide/components/activities/background-starts – David Wasser Mar 23 '22 at 10:38

0 Answers0