Question

I am showing a notification that starts a new activity. extra information passed with the intent is not available in the activity:

            Intent intent = new Intent(GlobalApplication.getAppContext(),
                    UserNotificationRequestOrderActivity.class);
            intent.putExtra(Constants.REQUEST_ORDER_INTENT_NAME,
                    command.getMessage());

            PendingIntent pIntent = PendingIntent.getActivity(
                    GlobalApplication.getAppContext(), 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT
                            | PendingIntent.FLAG_ONE_SHOT);

            // build notification
            // the addAction re-use the same intent to keep the example short
            Notification n = new Notification.Builder(
                    GlobalApplication.getAppContext())
                    .setContentTitle("Requesting Order")
                    .setContentText(command.getMessage())
                    .setSmallIcon(R.drawable.icon).setContentIntent(pIntent)
                    .setAutoCancel(true).getNotification();

            mNotificationManager.notify(0, n);

Here is the code in the activity to get the extras from the intent:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.request_order);

        String message = getIntent()
                .getStringExtra("REQUEST_ORDER_INTENT_NAME");
    }

message variable is always null.

Was it helpful?

Solution

I found the problem, it was a mistake in getting the intent name:

String message = getIntent()
                .getStringExtra("REQUEST_ORDER_INTENT_NAME");

should be

 String message = getIntent()
                .getStringExtra(Contants.REQUEST_ORDER_INTENT_NAME);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top