1

I am a beginner, and would be very grateful if anyone could help me out here.

I have read the android documentation guide and reference about some classes here, but I am not able to understand exactly what is happening.

I have mentioned my queries as comments in the code and then finally together.

In the android documentation, while creating a simple notification, this is the code they use:

NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(this)
    .setSmallIcon(R.drawable.notification_icon)
    .setContentTitle("My notification")
    .setContentText("Hello World!");

// We created an intent here!
Intent resultIntent = new Intent(this, ResultActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

// Now, what are we exactly doing below line... I don't understand the concept of parentStack
stackBuilder.addParentStack(ResultActivity.class);

// What is 'addNextIntent' exactly doing? I mean, there is only one intent right? What is this "Next" Intent?
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
    stackBuilder.getPendingIntent(
        0,
        PendingIntent.FLAG_UPDATE_CURRENT
    );

mBuilder.setContentIntent(resultPendingIntent);

NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(mId, mBuilder.build());
fsljfke
  • 431
  • 6
  • 14

1 Answers1

0

TaskStackBuilder is responsible for creating your app's activities stack. You can read more about them here.

When app is activated by the click on notification the resultIntent you've created is passed to the onNewIntent() method of the ResultActivity class. Some extra parameters could be passed with the intent - see this article for more details.

The intent could be handled by your code in the overriden onNewIntent in the ResultActivity.

Community
  • 1
  • 1
Mykola
  • 435
  • 4
  • 17