0

Widget(appwidgetprovider + service) を取得しました

このようにサブスレッドで getService() を使用します。

Intent intent = new Intent(context, this.getClass());    
intent.setAction(Intent.ACTION_VIEW);    
intent.setFlags(Intent.FLAGS_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TOP);      
intent.putExtra("test", test);    

Intent intent = new Intent(context, this.getClass());    
Integer requestCode = notDuplicateInteger;
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(), requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteView.setOnClickPendingIntent(R.id.test, pendingIntent, test);

この getService() は null を返すことがあります。

しかし、それがいつ起こったのか理解できません。

この null PendingIntent は updateAppWidget(provider, remoteView) で次の Nullpointer Exception が発生します

java.lang.NullPointerException
at android.widget.RemoteViews$SetOnClickPendingIntent.writeToParcel(RemoteViews.java:436)
at android.widget.RemoteViews.writeToParcel(RemoteViews.java:1660)
at android.os.Parcel.writeParcelable(Parcel.java:1168)
at android.widget.RemoteViews$ViewGroupAction.writeToParcel(RemoteViews.java:903)
at android.widget.RemoteViews.writeToParcel(RemoteViews.java:1660)
at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetProvider(IAppWidgetService.java:485)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:341)
at android.test.TestService$HandlerCallback.boolean handleMessage(android.os.Message)(SourceFile:423)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)   

私のサービスはサービスを拡張します。

AppWidgetProvider と ConfigureActivity(broadcast android.appwidget.action.APPWIDGET_CONFIGURE) を使用します。

ConfigureActivity は次のことを行います。

Intent intent = new Intent();
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);    
setResult(RESULT_OK, intent)    
4

0 に答える 0