Skip to content

Instantly share code, notes, and snippets.

@akbarsha03
Last active May 28, 2017 19:10
Show Gist options
  • Save akbarsha03/a1ff888bb6a5fd997182b2b5bdbd32e7 to your computer and use it in GitHub Desktop.
Save akbarsha03/a1ff888bb6a5fd997182b2b5bdbd32e7 to your computer and use it in GitHub Desktop.
NotificationCompat.Builder(this).apply builder@ { // object 1 reference
setSmallIcon(R.drawable.ic_launcher)
setContentTitle("My notification")
setContentText("Hello world!")
Intent(this, HomeActivity::class.java).apply resultIntent@ { // object 2 reference
TaskStackBuilder.create(this).apply {
addParentStack(HomeActivity::class.java)
addNextIntent(this@resultIntent)
this@builder.setContentIntent(getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT))
(this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).apply {
notify(101, this@builder.build())
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment