Get Latest Intent
android, android-intent
Solution
I think you need to override `onNewIntent` method to get the afterwards comming intents. It happens if your activity's launch mode is set to singleTop and the activity is not finished till it gets the second intent.
Problem
I'm Invoking an `Activity` from my `Service`. I do this whenever an event occurs and every time I pass a Serializable object via the Intent. The problem here is that when the Activity is invoked for the second time, it has the old Intent data and not the new one. So I'm sure that this is due to some mistake that I have made in the `Activity` class but I'm not able to figure it out. ``` public class ReceiveActivity extends Activity { AlertDialog alertDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Event"); CustomEvent custom= (CustomEvent) getIntent().getSerializableExtra("custom"); alertDialog.setMessage(custom.getName()); alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.setButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ReceiveActivity.this.finish(); } }); alertDialog.show(); } @Override protected void onPause() { if(alertDialog!=null) {alertDialog.dismiss();} super.onPause(); } @Override protected void onStop() { if(alertDialog!=null) {alertDialog.dismiss();} super.onStop(); } ``` and this is the code that I use to Invoke the Activity form the Service(Via a `Notification`) ``` Notification notification = new Notification(R.drawable.ic_launcher, "msg", System.currentTimeMillis()); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; Intent incoming =new Intent(this, ReceiveActivity.class); incoming.putExtra("custom",custom); PendingIntent contentIntent = PendingIntent.getActivity(this, 0,incoming, 0); notification.setLatestEventInfo(this, "msg","incoming", contentIntent); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify("Incoming", count++,notification); } ```