0

I have an AppWidget that interacts with two Activities. First Activity asks user to type in some text. Here's the code to start this Activity from AppWidget:

Intent promptIntent = new Intent(context,
        TransparentPromptActivity.class);
promptIntent.putExtra("appwidget_id", appWidgetId);
promptIntent.putExtra("message", incomingMessage);
PendingIntent promptPendingIntent = PendingIntent.getActivity(
        context, 0, promptIntent, 0);
views.setOnClickPendingIntent(R.id.app_widget_tv,
        promptPendingIntent);

This Activity sends the entered message back to the AppWidget which displays it. Then there's an Activity that shares the message, and here's the code to start this Activity:

Intent shareIntent = new Intent(context, MainActivity.class);
shareIntent.putExtra("message", incomingMessage);
PendingIntent sharePendingIntent = PendingIntent.getActivity(
        context, 0, shareIntent, 0);
views.setOnClickPendingIntent(R.id.app_widget_btn_share,
        sharePendingIntent);

As you can see, the message is stored in a local incomingMessage variable. However, when the second Activity is started, incomingMessage is empty, means the Intent contents are not updated when the variable value changes. How this effect can be achieved? Thanks in advance.

Egor
  • 39,695
  • 10
  • 113
  • 130

1 Answers1

0

How this effect can be achieved?

Use an appropriate flag on your getActivity() call, such as FLAG_UPDATE_CURRENT, if you are creating a PendingIntent on the same core Intent (e.g., for the same activity) and are changing extras.

That being said, since TransparentPromptActivity and MainActivity are not the same activity, FLAG_UPDATE_CURRENT will not help. Perhaps your issue is that incomingMessage is null in your second case.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491