Assume that I have a app-widget which contains an stack-view and four buttons.
I want to load different data into stack-view by clicking on each of those four buttons.
Things I know:
I know how to populate an stack view in app-widget by fetching data from a URL.
and I know how to call an intent in onUpdate to call RemoteViewsService and fill stack-view:
Intent intentNews = new Intent(context, StackWidgetService.class);
intentNews.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intentNews.setData(Uri.parse(intentNews.toUri(Intent.URI_INTENT_SCHEME)));
remoteViews.setRemoteAdapter(appWidgetIds[i], R.id.svShowContentOfApp, intentNews);
What I want to do:
how to implement onClick for each of my buttons to call different RemoteViewsService and load different content into my stack-view.
Edit:
I made some advance:
I figure it out that how to click on a button using this piece of code:
Intent intentClick = new Intent(context, getClass());
intentClick.setAction(ACTION);
PendingIntent PIClick = PendingIntent.getBroadcast(context, 0, intentClick, 0);
remoteViews.setOnClickPendingIntent(R.id.imageView, PIClick);
and in onReceive I can call RemoteViewsService like this:
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.total_app_widget);
if (ACTION.equals(intent.getAction())) {
//>>> for loading a data into stack-view
Intent intentNews = new Intent(context, StackWidgetServiceNews.class);
intentNews.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIdNews);
intentNews.setData(Uri.parse(intentNews.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(appWidgetIdNews, R.id.svShowContentOfApp, intentNews);
// -------------------------------------- loading a data into stack-view
ComponentName widget = new ComponentName(context, TotalAppWidget.class);
AppWidgetManager.getInstance(context).updateAppWidget(widget, views);
}
}
when I click on button, stackView disappears and empty-view shows instead. according to Logs everything is OK but stack-view never displays again. looks like remoteView doesn't became update?