I have a stack widget for my application, which currently just launches the main action when the widget is clicked. I want to change this, so the main activity provides information about which click has clicked. The object I want to transfer implements Parcelable and can be successfully transferred through the intent of the notification. However, it always seems to be null when it is associated with intent from the widget.
Any ideas?
StackWidgetProvider
// set intent for item click (opens main activity) Intent viewIntent = new Intent(context, DealPadActivity.class); viewIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); viewIntent.setData(Uri.parse(viewIntent.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent viewPendingIntent = PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.stack_view, viewPendingIntent);
StackWidgetService
public RemoteViews getViewAt(int position) { RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.stack_widget_item); if (position < mWidgetItems.size()){ rv.setTextViewText(R.id.stack_widget_title, mWidgetItems.get(position).title); rv.setTextViewText(R.id.stack_widget_price, mWidgetItems.get(position).price); rv.setTextViewText(R.id.stack_widget_heat, mWidgetItems.get(position).heat); Bitmap picture = imageLaoder.getBitmap(mWidgetItems.get(position).imageUrl, true) ; rv.setImageViewBitmap(R.id.stack_widget_image, picture); } Intent fillInIntent = new Intent(); Bundle extras = new Bundle(); extras.putInt(StackWidgetProvider.EXTRA_ITEM, position); extras.putParcelable("notificationDeal", new Deal(...)); fillInIntent.putExtras(extras); rv.setOnClickFillInIntent(R.id.stack_widget_layout, fillInIntent); return rv; }
Mainactivity
Bundle data = queryIntent.getExtras(); if (data!=null){ // check to see if from widget or notification Deal deal = data.getParcelable("notificationDeal"); if (deal!=null){ // ****ALWAYS NULL FROM WIDGET**** Log.d(this.getClass().getSimpleName(), "going to show passed deal"); onDealSelected(deal); } int i = data.getInt("com.bencallis.dealpad.stackwidget.EXTRA_ITEM"); Log.d(this.getClass().getSimpleName(), "pressed widget is: " + i); **WIDGET ITEM POSITION AS EXPECTED **
** Update **
This seems to be a marshalling issue (specifically for him)
E/Parcel: Class not found when unmarshalling: com.bencallis.abc.Deal, e: java.lang.ClassNotFoundException: com.bencallis.abc.Deal
I imported the Deal class into a StackWidgetService, and I tried installing the class loader, but that doesn't seem to help.
The Transaction add-on is successfully used in the main actions of the application, I have this problem with widgets.
Deal class
public Deal(Parcel in) { in.readParcelable(Deal.class.getClassLoader()); } @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(title); ... } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Deal createFromParcel(Parcel in) { return new Deal(in); } public Deal[] newArray(int size) { return new Deal[size]; } };