startActivity() from BroadcastReceiver
问题 I am trying to autostart my nightclock application on charging using the following BroadcastReceiver implemented in the onPause() method: BroadcastReceiver test = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { unregisterReceiver(this); Intent i = new Intent(context, NightClock.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }; registerReceiver(test, new IntentFilter(Intent.ACTION_POWER_CONNECTED)); The onReceive()