Skip to content

Instantly share code, notes, and snippets.

@akbarsha03
Created May 28, 2017 19:01
Show Gist options
  • Save akbarsha03/19948895c4db1945636396c51fd701fe to your computer and use it in GitHub Desktop.
Save akbarsha03/19948895c4db1945636396c51fd701fe to your computer and use it in GitHub Desktop.
// object 1
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// object 2
Intent resultIntent = new Intent(this, ResultActivity.class);
// object 3
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ResultActivity.class);
stackBuilder.addNextIntent(resultIntent);
// object 4
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
// object 5
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(mId, mBuilder.build());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment