Blog Infos
Author
Published
Topics
,
Author
Published
Did you ever notice?

What is a Notification trampoline?
Android12 restrictions
Error message in logcat
Indirect notification activity start (trampoline) from PACKAGE_NAME, \
this should be avoided for performance reasons.
Sample code that will create this issue
class NotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// from Android12 this will not work
// Indirect notification activity start (trampoline) from PACKAGE_NAME, \ this should be
//avoided for performance reasons.
context.startActivity(Intent(context, NotificationTrampolineActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK
})
}
}

NotificationReceiver.kt

 

val broadcastIntent = Intent(context.applicationContext, NotificationReceiver::class.java)
val actionIntent = PendingIntent.getBroadcast(
context.applicationContext,
0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT or
// mutability flag required when targeting Android12 or higher
PendingIntent.FLAG_IMMUTABLE
)
// notification code
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Android12")
.setContentText("Notification trampoline restrictions")
.addAction(R.mipmap.ic_launcher, "Open activity from receiver", actionIntent)
.setAutoCancel(true)
.build()
notificationManager.notify(getUniqueId(), notification)

NotificationWithReceiverIntent.kt

 

Identify which app components act as notification trampolines
adb shell dumpsys activity service \ com.android.systemui/.dump.SystemUIAuxiliaryDumpService
A section of the output includes the text "NotifInteractionLog".
This section contains the information that's necessary to identify the component that starts as the result of a notification tap.

Job Offers

Job Offers

There are currently no vacancies.

OUR VIDEO RECOMMENDATION

, ,

Migrating to Jetpack Compose – an interop love story

Most of you are familiar with Jetpack Compose and its benefits. If you’re able to start anew and create a Compose-only app, you’re on the right track. But this talk might not be for you…
Watch Video

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer for Jetpack Compose
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engin ...
Google

Migrating to Jetpack Compose - an interop love story

Simona Milanovic
Android DevRel Engineer f ...
Google

Jobs

Toggle the behavior

App compatibility flag

val notificationTrampolineActivityIntent =
Intent(context.applicationContext, NotificationTrampolineActivity::class.java)
// Create the TaskStackBuilder
val resultPendingIntent: PendingIntent? = TaskStackBuilder.create(context).run {
// Add the intent, which inflates the back stack
addNextIntentWithParentStack(notificationTrampolineActivityIntent)
// Get the PendingIntent containing the entire back stack
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT or
// mutability flag required when targeting Android12 or higher
PendingIntent.FLAG_IMMUTABLE)
val notification = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Android12")
.setContentText("Notification trampoline restrictions fix")
.addAction(R.mipmap.ic_launcher, "Open activity", resultPendingIntent)
.setAutoCancel(true)
.build()
notificationManager.notify(getUniqueId(), notification)

YOU MAY BE INTERESTED IN

YOU MAY BE INTERESTED IN

blog
In this article, we will go through the improvements that Android12 brings for Exact…
READ MORE
blog
Splash screen is the initial screen you’ll see when you open your app. It…
READ MORE
blog
Android 12 brought several changes and one of them, that raises some questions, is…
READ MORE
blog
During I/O 2021, Google announced the latest stage for Material Design, Material You (or…
READ MORE

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu