什么时候getService()返回null?

时间:2013-05-25 10:31:04

标签: java android android-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异常

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(广播android.appwidget.action.APPWIDGET_CONFIGURE)。

ConfigureActivity会执行以下操作。

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

0 个答案:

没有答案