突然间,我开始收到相当多的崩溃报告,声称android.app.PendingIntent.getActivity方法不存在.
有人知道是什么原因引起的吗?
java.lang.NoSuchMethodError: androID.app.PendingIntent.getActivity at com.example.notification.NotificationHelper.showNotification(NotificationHelper.java:37) at com.example.notification.NotificationHelper.showNotification(NotificationHelper.java:19) at com.example.content.sync.userdata.TaskSynchronizer.onResultReceived(TaskSynchronizer.java:142) at com.example.content.sync.BulkRequest.onResultReceived(BulkRequest.java:172) at com.example.content.sync.SyncAdapterHelper.pushOrPull(SyncAdapterHelper.java:201) at com.example.content.sync.SyncAdapterHelper.syncAll(SyncAdapterHelper.java:60) at com.example.content.sync.SyncAdapter.onPerformSync(SyncAdapter.java:139) at androID.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:247)
以下是我的NotificationHelper类:
public class NotificationHelper { public static voID showNotification( Context context, String Title, String content, MenuItem itemToStart ) { showNotification(context, Title, content, itemToStart, null, itemToStart.ID ); } public static voID showNotification( Context context, String Title, String content, MenuItem itemToStart, Bundle extras ) { showNotification(context, Title, content, itemToStart, extras, itemToStart.ID ); } public static voID showNotification( Context context, String Title, String content, MenuItem itemToStart, Bundle extras, int notificationID ) { /* * Check if user has Disabled notifications */ if ( !ProfileManager.areNotificationsEnabled( context ) ) { return; } NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Intent contentIntent = new Intent( context, LauncherActivity.class ); contentIntent.putExtra( MFMainActivity.EXTRA_START_MENUITEM_ID, itemToStart.ID ); builder.setSmallicon( R.drawable.ic_stat_notify ) .setautoCancel( true ) .setContentTitle( Title ) .setContentText( content ) .setContentIntent( PendingIntent.getActivity(context, 0, contentIntent, Intent.FLAG_ACTIVITY_NEW_TASK, extras ) ); notificationmanager nm = (notificationmanager) context.getSystemService( Context.NOTIFICATION_SERVICE ); nm.notify( notificationID, builder.build() ); }}
更新:正如Tushar指出的那样,我已经开始将PendingIntent.getActivity()方法与Bundle参数一起使用.这个方法首先在API 16中引入,它导致所有具有早期API的设备崩溃.
我的解决方案是调用contentIntent.replaceExtras(extras)并将内容Intent中的额外内容传递给getActivity()方法.
解决方法:
getActivity(Context context, int requestCode, Intent intent, int flags, Bundle options)
仅在AndroID API 16(4.1)中引入.如果你在下面的任何东西上运行你的应用程序,它将抛出此异常.
您可能希望使用API 1引入的getActivity()版本,该版本具有签名(通知缺少Bundle):
getActivity(Context context, int requestCode, Intent intent, int flags)
Source
总结以上是内存溢出为你收集整理的java.lang.NoSuchMethodError:android.app.PendingIntent.getActivity全部内容,希望文章能够帮你解决java.lang.NoSuchMethodError:android.app.PendingIntent.getActivity所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)