Problem sending notification with parameters

Asked

Viewed 83 times

1

I’m having problems in an android app, when trying to send a notification everything happens 100% until you arrive at the opening of the notification Activity.

This call Activity needs a "store" parameter and I am unable to send it via notification.

Look at 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?

  • Can you show how you try to get the parameter? Where does the error occur? Thanks!

  • Of course Thiago, Follow: store = (Store) this.getIntent(). getSerializableExtra("store");

1 answer

1

The problem is that you are sending a String and expect to receive a Store type object. What you send as String is the Store ID. You can probably recover that Store from the sent ID. Try to change the error line to:

String id = getIntent().getStringExtra("store");
  • It worked, that’s right Diego! Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.