我正在处理小部件点击事件。当应用程序在后台运行时,它能够完美工作。但是,在关闭应用程序后,它会返回错误。请告诉我是否有任何解决方案。
E/RemoteViews: Cannot send pending intent due to unknown exception:
11-25 17:50:31.599 2119-2119/? E/RemoteViews: android.content.ActivityNotFoundException
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at com.android.launcher3.Launcher.startIntentSenderForResult(Launcher.java:2060)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.app.Activity.startIntentSender(Activity.java:4292)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.content.ContextWrapper.startIntentSender(ContextWrapper.java:390)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.RemoteViews$OnClickHandler.onClickHandler(RemoteViews.java:217)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.RemoteViews$SetPendingIntentTemplate$1.onItemClick(RemoteViews.java:495)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.AdapterView.performItemClick(AdapterView.java:310)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.AbsListView$PerformClick.run(AbsListView.java:3042)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.widget.AbsListView$3.run(AbsListView.java:3879)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.os.Handler.handleCallback(Handler.java:739)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.os.Handler.dispatchMessage(Handler.java:95)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.os.Looper.loop(Looper.java:148)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at android.app.ActivityThread.main(ActivityThread.java:5417)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at java.lang.reflect.Method.invoke(Native Method)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-25 17:50:31.599 2119-2119/? E/RemoteViews: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
现在我已经在widgetprovider类中附加了我的代码
private RemoteViews updateWidgetListView(Context context, int appWidgetId) {
// which layout to show on widget
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.task_list_widget);
// RemoteViews Service needed to provide adapter for ListView
Intent svcIntent = new Intent(context, WidgetService.class);
// passing app widget id to that RemoteViews Service
svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
// setting a unique Uri to the intent
// don't know its purpose to me right now
svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
// setting adapter to listview of the widget
remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, svcIntent);
// setting an empty view in case of no data
remoteViews.setEmptyView(R.id.widget_list, R.id.txt_no_data);
Intent startActivityIntent = new Intent(context, getClass());
// startActivityIntent.putExtra("from", "widget");
startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityIntent.setAction("list");
PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.id.widget_list, startActivityPendingIntent);
// remoteViews.setOnClickPendingIntent(R.id.btn_widget_sos, startActivityPendingIntent);
// Intent intent = new Intent(context, Home.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// // Get the layout for the App Widget and attach an on-click listener to the button
// remoteViews.setOnClickPendingIntent(R.id.widget_list, pendingIntent);
return remoteViews;
}