当我尝试创建通知时,我的应用程序总是崩溃,只在Android 3.0上崩溃。
03-05 21:23:00.774: ERROR/ActivityManager(66): Activity Manager Crash
03-05 21:23:00.774: ERROR/ActivityManager(66): java.lang.IllegalArgumentException: Null intent at index 0
03-05 21:23:00.774: ERROR/ActivityManager(66): at com.android.server.am.ActivityManagerService.getIntentSender(ActivityManagerService.java:3907)
03-05 21:23:00.774: ERROR/ActivityManager(66): at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:799)
03-05 21:23:00.774: ERROR/ActivityManager(66): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:1516)
03-05 21:23:00.774: ERROR/ActivityManager(66): at android.os.Binder.execTransact(Binder.java:320)
03-05 21:23:00.774: ERROR/ActivityManager(66): at dalvik.system.NativeStart.run(Native Method)
03-05 21:23:00.784: WARN/dalvikvm(458): threadid=9: thread exiting with uncaught exception (group=0x40014760)
03-05 21:23:00.814: ERROR/AndroidRuntime(458): FATAL EXCEPTION: Thread-10
03-05 21:23:00.814: ERROR/AndroidRuntime(458): java.lang.IllegalArgumentException: Null intent at index 0
03-05 21:23:00.814: ERROR/AndroidRuntime(458): at android.os.Parcel.readException(Parcel.java:1326)
03-05 21:23:00.814: ERROR/AndroidRuntime(458): at android.os.Parcel.readException(Parcel.java:1276)
03-05 21:23:00.814: ERROR/AndroidRuntime(458): at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:2356)
03-05 21:23:00.814: ERROR/AndroidRuntime(458): at android.app.PendingIntent.getActivity(PendingIntent.java:195)
03-05 21:23:00.814: ERROR/AndroidRuntime(458): at com.perlapps.myantivirus.scanmethodes.UpdateDatabase$1.run(UpdateDatabase.java:244)
有人知道如何解决它吗?
编辑:完美地适用于1.5到2.3
NotificationManager meinNM = (NotificationManager) oContext.getSystemService(Context.NOTIFICATION_SERVICE);
Notification meinNotofication = new Notification(R.drawable.icon,"HELLO",System.currentTimeMillis());
PendingIntent pendingIntent = PendingIntent.getActivity(oContext.getApplicationContext(),0, null, 0);
meinNotofication.setLatestEventInfo(oContext.getApplicationContext(),"HELLO","HELLO",pendingIntent);
meinNM.notify(97, meinNotofication);
答案 0 :(得分:2)
使用有效的PendingIntent
。您的作品无效 - null
不是getActivity()
的有效第三个参数。另外,摆脱getApplicationContext()
- oContext
是Context
,这就是你所需要的。