Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 9 API 28 FLAG_ACTIVITY_NEW_TASK, is it really enforced?

Tags:

android

According to new behavior documented here https://developer.android.com/about/versions/pie/android-9.0-changes-all#fant-required starting activities from non-activity context requires FLAG_ACTIVITY_NEW_TASK flag, perhaps...

So I have created sandbox app that can launch activity of another apps by package name and activity name. The core function used to launching, looks like this:

fun Context.startActivity(packageName: String, activityName: String) {
    applicationContext.startActivity(Intent(Intent.ACTION_MAIN).apply {
        component = ComponentName(packageName, activityName)
    })
}

What is odd, by calling this function I can succesfully start any exported activity without passing FLAG_ACTIVITY_NEW_TASK. It is quite different from what google saying about that. Or maybe I wrongly understand this new behavior requirements?

Off course I tested this on API 28 but also on lower API's.

Can someone explain in which cases this new behavior can breaks any feature that works on older APIs?

like image 881
yaneq6 Avatar asked Nov 07 '22 00:11

yaneq6


1 Answers

As per this change it seems to be a restriction when FLAG_ACTIVITY_NEW_TASK is not set while launching an activity from a non-activity context.

StartActivity method in Activity.java is overriden and avoid this restriction.

like image 165
Ayyappa Avatar answered Nov 14 '22 22:11

Ayyappa