我正在为我的应用程序开发一个小部件,但我遇到了一个问题:
没有调用我的android.widget.RemoteViewsService类的OnGetViewFactory方法!
我的代码:
维护服务

  this.views = new RemoteViews(this.ctx.getPackageName(), i);
  Intent localIntent = new Intent(this.ctx, MyWidgetService.class);
  localIntent.putExtra("WidgetId", param);
  localIntent.setData(Uri.parse(localIntent.toUri(Intent.URI_INTENT_SCHEME)));

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  this.views.setRemoteAdapter(R.id.weather_list, localIntent);
  else
  this.views.setRemoteAdapter(param, R.id.weather_list, localIntent);

  ComponentName localComponentName = new ComponentName(this.ctx, MyWidgetProvider.class);
  AppWidgetManager localAppWidgetManager = AppWidgetManager.getInstance(this.ctx);
  localAppWidgetManager.notifyAppWidgetViewDataChanged(param, R.id.weather_list);
  localAppWidgetManager.updateAppWidget(param, this.views);

MyWidgetService服务
我的类扩展了remoteviewsservice并具有以下代码
@Override
    public RemoteViewsFactory onGetViewFactory(Intent intent) {
        // TODO Auto-generated method stub
        System.out.println("test");
        return null;
    }

MyWidgetProvider提供程序
我的类扩展了appwidgetprovider
有人能帮我吗?
我的密码怎么了?
谢谢:-)
编辑:是的,但是当我放置断点或日志时,它是相同的。

最佳答案

您在AndroidManifest.xml中申报过服务吗?

<service
     android:name="com.mypackage.MyWidgetService"
     android:exported="false"
     android:permission="android.permission.BIND_REMOTEVIEWS" >
</service>

关于android - onGetViewFactory未调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18550414/

10-10 22:21