Hii I am trying to make a widget with a gridview in it. The gridview Items showing thumbnail of movies. When I click on the Grid Item the particular movie should be open in Application. But when I click on any Item then intent is fired to open same movie each time. I mean to say in putextra() Iam sending the movie url but it is sending same url on every click.
code
public RemoteViews getViewAt(int position) {
// position will always range from 0 to getCount() -
// We construct a remote views item based on our widget item xml file,
// and set the
// text based on the position.
RemoteViews rv = new RemoteViews(mContext.getPackageName(),
R.layout.widget_item);
try {
rv.setImageViewBitmap(R.id.widget_item, image_url.get(position));
rv.setTextViewText(R.id.program_id,programId.get(position));
} catch (Exception e) {
// TODO: handle exception
}
Bundle extras = new Bundle();
extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
Intent clickIntent = new Intent(mContext, MainActivity.class);
//Bundle bundle.("homeUrl", programId.get(position));
Bundle bundle=new Bundle();
bundle.putString("homeUrl", programId.get(position));
clickIntent.putExtras(bundle);
try{
clickIntent.putExtra("homeUrl",programId.get(position));
}
catch (Exception e) {
// TODO: handle exception
}
PendingIntent pendingIntent = PendingIntent.getActivity(mContext,0 ,
clickIntent,PendingIntent.FLAG_UPDATE_CURRENT);
rv.setOnClickPendingIntent(R.id.widget_item, pendingIntent);
// System.out.println("new ="+bundle);
try {
System.out.println("Loading view " + position);
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Return the remote views object.
return rv;
}
Provider class;
@Override
public void onReceive(Context context, Intent intent) {
AppWidgetManager mgr = AppWidgetManager.getInstance(context);
super.onReceive(context, intent);
if (intent.getAction().equals(TOAST_ACTION)) {
int appWidgetId = intent.getIntExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
int viewIndex = intent.getIntExtra(EXTRA_ITEM, 0);
String nn=intent.getStringExtra(ETRA_ID);
}
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// update each of the widgets with the remote adapter
for (int i = 0; i < appWidgetIds.length; ++i) {
// Here we setup the intent which points to the StackViewService
// which will
// provide the views for this collection.
Intent intent = new Intent(context, StackWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetIds[i]);
// When intents are compared, the extras are ignored, so we need to
// embed the extras
// into the data so that the extras will not be ignored.
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews rv = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);
// The empty view is displayed when the collection has no items. It
// should be a sibling
// of the collection view.
rv.setEmptyView(R.id.stack_view,R.id.empty_view);
Intent toastIntent = new Intent(context, StackWidgetProvider.class);
toastIntent.setAction(StackWidgetProvider.TOAST_ACTION);
toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent toastPendingIntent = PendingIntent.getBroadcast(
context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}