我正在为我的应用开发一个Widget,我遇到了一个问题:
我的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
任何人都可以帮助我吗? 我的代码有什么问题?
谢谢: - )
编辑:是的,但是当我放置断点或日志时,它是相同的。
答案 0 :(得分:4)
您是否在AndroidManifest.xml
宣布了服务?
<service
android:name="com.mypackage.MyWidgetService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" >
</service>