这里是代码:
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, intent.getAction(), Toast.LENGTH_SHORT).show();
Log.i(TAG, "This is the broadcast receiver");
switch(intent.getAction()) {
case Intent.ACTION_BOOT_COMPLETED: {
mMeetingRoomDeviceSettings = SharedPreferenceManager.getSharedPreferenceValues(context);
// If you need to launch on device restart.
if(mMeetingRoomDeviceSettings.getLaunchOnBootup()) {
Intent configurationIntent = new Intent(context, ConfigureMeetingRoomActivity.class);
configurationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(configurationIntent);
Log.i(TAG, "Everything went fine.");
}
break;
}
}
}
我不知道为什么,但是startActivity()根本不启动活动。
正在显示日志:
2020-03-06 15:19:06.523 8833-8833/com.eurofins.android.myapplication I/MeetingRoomBroadcast: This is the broadcast receiver
2020-03-06 15:19:06.571 8833-8833/com.eurofins.android.myapplication I/MeetingRoomBroadcast: Everything went fine.
要从广播接收器开始活动,请参见以下代码段:
Intent configurationIntent= new Intent(context.getApplicationContext(), ConfigureMeetingRoomActivity.class);
context.startActivity(configurationIntent);
您使用了上下文而不是context.getApplicationContext()。
或者只是尝试在没有任何标志的情况下开始活动。