8 2 | I am trying to autostart my nightclock application on charging using the following BroadcastReceiver implemented in the onPause() method:
The onReceive() method is fired when the USB-cable is plugged in, but the activity doesn't start. However the log shows this:
Any ideas why the log says the activity is started, but nothing happens?
| |||
feedback |
6 | If your goal is that you want NightClock to be started whenever an ACTION_POWER_CONNECTED broadcast is sent, your approach of using a BroadcastReceiver is fine. However, do not register it from an activity. Rather, register it in the manifest:
Then, have your BroadcastReceiver as a public Java class (here named OnPowerReceiver , though you can call it whatever you want), and have it call startActivity() .Bear in mind that users probably do not want you doing this. There are many other cases for connecting a phone to power besides starting a "night clock". I humbly suggest you simply let users start your activity via the home screen. |
FLAG_ACTIVITY_NEW_TASK
? Also also, is the activity that registered thisBroadcastReceiver
still around when ACTION_POWER_CONNECTED occurs? – CommonsWare Oct 3 '10 at 13:50BroadcastReceiver
is registered in the same activity which it should start. This activity is still running in the background (the LogCat app has been brought to front). If this activity is killed in the taskmanager, theBroadcastReceiver
doesn't seem to trigger at all. Is this approach to autostart my app wrong from the beginning? – Gubbel Oct 3 '10 at 14:47