Problem sending notification with parameters

1

I'm having problems in an android app, when trying to send a notification everything happens 100% until I get to open the notification activity.

This calling activity needs a "store" parameter and I'm not able to send it via notification.

See the sources below:

private void Notify(String notificationTitle, String notificationMessage){
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    @SuppressWarnings("deprecation")

    Notification notification = new Notification(R.drawable.header_logo,"New Message", System.currentTimeMillis());
    Intent notificationIntent = new Intent(NewReviewActivity.this,ReviewActivity.class);
        notificationIntent.putExtra("store",String.valueOf(store.getStore_id()));

    PendingIntent pendingIntent = PendingIntent.getActivity(NewReviewActivity.this, 0, notificationIntent, 0);


    notification.vibrate = new long[]{150, 300, 150, 600};
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    notification.setLatestEventInfo(NewReviewActivity.this, notificationTitle, notificationMessage, pendingIntent);
    notificationManager.notify(9999, notification);
}

And my logcat:

  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.projects.storefinder/com.projects.activities.ReviewActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to com.models.Store

It is clear that the problem is that the parameter is not being properly passed.

Could you help me?

    
asked by anonymous 20.04.2016 / 02:47

1 answer

1

The problem is that you are sending a String and expect to receive an object of type Store. What you submit as String is the Store ID. You can probably recover this Store from the submitted ID. Try changing the line that gives error to:

String id = getIntent().getStringExtra("store");
    
20.04.2016 / 03:23