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


    Senior Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Android Software Engineer (f/m/d)

    Paradox Cat GmbH
    Munich
    • Full Time
    apply now

    Android Test Automation Engineer

    Komoot
    Remote
    • Full Time
    apply now

OUR VIDEO RECOMMENDATION

, ,

From Scoped Storage to Photo Picker: Everything to know about Storage

Persistence is a core element of every mobile app. Android provides different APIs to access or expose files with different tradeoffs.
Watch Video

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer advocate
Google

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer ad ...
Google

From Scoped Storage to Photo Picker: Everything to know about Storage

Yacine Rezgui
Android developer advocat ...
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