我有一个活动允许用户通过选择日期和时间来安排活动。我已经使用 AlarmManager 完成了
Intent i=new Intent(context, AlarmReceiver.class);
i.putExtra("status",status);
i.putExtra("mode",mode);
PendingIntent p=PendingIntent.getBroadcast(context, id, i, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarms.set(AlarmManager.RTC_WAKEUP, sched_time, p);
在广播接收器中启动了一个新的活动
@Override
public void onReceive(Context context, Intent data) {
// Start the scheduled post
String status=data.getExtras().getString("status");
int mode=data.getExtras().getInt("mode");
Intent i=new Intent(context,PostScheduled.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("status", status);
i.putExtra("mode", mode);
context.startActivity(i);
}
在模拟器中,此代码运行良好,但在实际设备(运行 android 2.3.3)中,它在该行崩溃
PendingIntent p=PendingIntent.getBroadcast(context, id, i, PendingIntent.FLAG_CANCEL_CURRENT);
这是堆栈跟踪
java.lang.IllegalArgumentException: Can't use FLAG_RECEIVER_BOOT_UPGRADE here
at android.os.Parcel.readException(Parcel.java:1326)
at android.os.Parcel.readException(Parcel.java:1276)
at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:2254)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:230)
at com.social.autofunnystatus.ScheduleDialog.onClick(ScheduleDialog.java:158)
at android.view.View.performClick(View.java:2538)
at android.view.View$PerformClick.run(View.java:9152)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
有人知道出了什么问题吗?