Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet133/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   129   130   131   132   133   134   135   136   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

151
CHAPTER 8: APIs
android:name=".MainActivity"
... >

android:name=".ResultActivity"
android:parentActivityName=".MainActivity" />
...

You can then use a TaskStackBuilder to inflate a task stack for the intent called.
// Create an Intent for the Activity you want to start
val resultIntent =
Intent(this, ResultActivity::class.java)
// Create the TaskStackBuilder
val stackBuilder = TaskStackBuilder.create(this)
stackBuilder.
addNextIntentWithParentStack(resultIntent)
// Get the PendingIntent containing the back stack
val resultPendingIntent =
stackBuilder.getPendingIntent(
0, PendingIntent.FLAG_UPDATE_CURRENT)
// -> this can go to .setContentIntent() inside
// the builder
For more details about activities and task management, please see Chapter 
3
.
Grouping Notifications
Beginning with API level 24 (Android 7.0), notifications can be grouped to improve the 
representation of several notifications that are related in some way. To create such a group
all you have to do is add the following to the builder chain, with GROUP_KEY being a string of 
your choice:
.setGroup(GROUP_KEY)
If you need a custom sorting, the default is to sort by incoming date; you can use the 
method setSortKey() from the builder. Sorting then happens lexicographically given that 
key. A grouping inside the notification drawer might look like Figure 
8-4
.


152
CHAPTER 8: APIs
For API levels below 24 where some kind of Android-managed autosummary for groups 
is not available, you can add a notification summary. To do so, just create a notification 
like any other notification, but additionally call .setGroupSummary(true) inside the builder 
chain. Make sure all the notifications from the group and the summary use the same 
setGroup(GROUP_KEY).
For the summary you might want to tailor the display style for displaying an appropriate 
number of summary items. For this aim, you can use a construct like the following inside the 
builder chain:
.setStyle(NotificationCompat.InboxStyle()
.addLine("MasterOfTheUniverse Go play PacMan")
.addLine("Silvia Cheng Party tonite")
.setBigContentTitle("2 new messages")
.setSummaryText("xyz@example.com"))

Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   129   130   131   132   133   134   135   136   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling