0

I have an activity A that is triggered like the starting activity.

in oncreate, if some data is missing, activity A creates a new activity B with a startactivity. It also calls finish() after that. Like this way, I obtain a backstack with only activity B in it.

So far, so good.

Now, when some tasks are completed in activity B, it calls startactivity(activityA) and subsequently calls on itself finish(). It also passes some extras, and activity A will read them without any problem.

private void goToA(){
    Intent goHome= new Intent(this, A.class);
    goHome.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
    goHome.putExtra("test", "test 1");

    startActivity(goHome);
    finish();
}

Now I have a backstack formed by nothing but activity A. Right? In fact, if I press "back" I go back to the launcher.

Ok, now, on activity A, during an operation I create a notification with a pendingintent in it. The intent calls the activity A itself with new extras values, but with the same parameters passed from activity B before.

Intent notifyIntent= new Intent(MyApplication.getAppContext(), A.class);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
notifyIntent.putExtra("test", "test 2");
PendingIntent intentHome= PendingIntent.getActivity(MyApplication.getAppContext(),2,notifyIntent, PendingIntent.FLAG_CANCEL_CURRENT);

Notification notificationToSend= new Notification(R.drawable.icon_notification, "Tracciamento avviato", System.currentTimeMillis());
notificationToSend.setLatestEventInfo(MyApplication.getAppContext(), "Tracciamento sgàget!","Seleziona per tornare al tracciamento", intentHome);
notificationToSend.flags |= Notification.DEFAULT_SOUND;
notificationToSend.flags |= Notification.FLAG_NO_CLEAR;

Now, if I go back to the launcher, I open the notification area and I tap my notification, I go back to the activity A as expected, but when I read the extras in onResume, I get the ones passed by activity B ("test 1")!

I don't think this is a common "update your pendingintent properly" issue, cause the first startactivity does not involve any pendingintent at all. Any suggestion?

Bertuz
  • 2,390
  • 3
  • 25
  • 50
  • In ActivityA, override `onNewIntent()`. Add logging there to see if it is getting called when you click the notification. I expect that it is. In that case, when you check the extras in `onResume()` you are seeing the extras that were passed when ActivityA was originally created. – David Wasser Jun 04 '13 at 21:49
  • I've just found the error (a very beginner one). As soon as I have five minutes free I'll write the solution. To make it simple: the activity neither wasn't register in the manifest with "single-instance" nor the intent had a "new-task" in it. Android explains this behaviour very well in its documentation. – Bertuz Jun 05 '13 at 00:44

0 Answers0