For various reasons, my app creates entries in the notification bar. When the user clicks on the notification, I want to display a custom activity that presents the entry in a certain format.
Intent intent = new Intent(applicationContext, TextMessageViewerActivity.class);
intent.putExtra("text_message", someText);
PendingIntent contentIntent = PendingIntent.getActivity(applicationContext, 0, intent, 0);
// now create a notification and post it. no fancy flags
It all boils down to sending a string via an Intent extra, and displaying that in my Activity. What happens is that the first Intent that gets delivered to my Activity gets "stuck" somehow, and all further Intents delivered to it display the only the first Intent's extra.
public class TextMessageViewerActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.text_viewer);
}
@Override
public void onResume()
{
super.onResume();
Intent startingIntent = getIntent();
String message = startingIntent.getStringExtra("text_message");
String displayMessage = message != null ? message : "No message found";
((TextView)findViewById(R.id.text_viewer_text_id)).setText(displayMessage);
}
}
What am I not understanding about the Android Activity lifecycle?