【问题标题】:onGetViewFactory not calledonGetViewFactory 未调用
【发布时间】:2013-08-31 16:44:24
【问题描述】:

我正在为我的应用程序开发一个小部件,但我遇到了问题:

我的 android.widget.RemoteViewsService 类的 onGetViewFactory 方法没有被调用!

我的代码:

IntentService

  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

有人可以帮我吗? 我的代码有什么问题?

谢谢你:-)

编辑:是的,但是当我放置断点或日志时,它是一样的。

【问题讨论】:

  • 不要使用System.out.println(...); - 改为登录。您将无法在设备上看到println

标签: android android-widget android-appwidget


【解决方案1】:

您是否在AndroidManifest.xml 中声明了您的服务?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-01
    • 1970-01-01
    • 2018-01-09
    相关资源
    最近更新 更多