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


    Kotlin Multiplatform Mobile Developer

    Touchlab
    Remote
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

Exploring Dynamic Feature Modules

Dynamic Feature Modules were announced in 2018 as a new way to modularize and deliver Android apps. It presents a way to decouple features entirely from one another, and avoid a “monoapp” which depends on…
Watch Video

Exploring Dynamic Feature Modules

Alec Strong
Android Developer
CashApp

Exploring Dynamic Feature Modules

Alec Strong
Android Developer
CashApp

Exploring Dynamic Feature Modules

Alec Strong
Android Developer
CashApp

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.

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

Menu