Start activity from receiver in Android Q
It is very important for the feature to start the activity immediately, so there is a way to continue starting the activity from the receiver?
No, sorry. Use a high-priority notification, so it appears in "heads-up" mode. The user can then rapidly tap on it to bring up your activity.
How to trigger a launch Activity intent when my app is closed on Android 10/Q?
As of Android 10 (API level 29), you cannot start activities from the background anymore.
There are a number of exceptions to this rule that may or may not apply to your given scenario.
If none of the exceptions apply, you might want to consider displaying a high-priority notification, possibly with a full-screen Intent.
Can't start activity from BroadcastReceiver on android 10
Android 10's restriction on background activity starts was announced about six months ago. You can read more about it in the documentation.
Use a high-priority notification, with an associated full-screen Intent
, instead. See the documentation. This sample app demonstrates this, by using WorkManager
to trigger a background event needing to alert the user. There, I use a high-priority notification instead of starting the activity directly:
val pi = PendingIntent.getActivity(
appContext,
0,
Intent(appContext, MainActivity::class.java),
PendingIntent.FLAG_UPDATE_CURRENT
)
val builder = NotificationCompat.Builder(appContext, CHANNEL_WHATEVER)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Um, hi!")
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setFullScreenIntent(pi, true)
val mgr = appContext.getSystemService(NotificationManager::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mgr.getNotificationChannel(CHANNEL_WHATEVER) == null
) {
mgr.createNotificationChannel(
NotificationChannel(
CHANNEL_WHATEVER,
"Whatever",
NotificationManager.IMPORTANCE_HIGH
)
)
}
mgr.notify(NOTIF_ID, builder.build())
Related Topics
Android Background Service Is Restarting When Application Is Killed
Custom Converter for Retrofit 2
Upgraded to Android Studio 3.4 - Aapt2Internalexception: Aapt2: Daemon Startup Failed
How to Set Up Screen Lock with a Password Programmatically
Fragment Replacing in Recyclerview Item
How to Draw Outside the Bounds of an Android Canvas
Android.Os.Networkonmainthreadexception with Android 4.2
How to Open Phones Gallery Through Code
Launch Android Application from a Browser Link
Quality Selector for Exoplayer 2
Java.Lang.Illegalargumentexception: Can Only Use Lower 16 Bits for Requestcode
Android Convert Date and Time to Milliseconds
How to Retrieve Data from Cursor Class
How to Get Screen Size of Device
Google Play Services V13 Error Meta-Data in Androidmanifest
Android Linkify Text - Spannable Text in Single Text View - as Like Twitter Tweet