flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.93k stars 27.17k forks source link

[url_launcher] Support FLAG_ACTIVITY_NEW_TASK Intent on Android #153901

Open bruce3x opened 3 weeks ago

bruce3x commented 3 weeks ago

Use case

I want to launch a Uri in a new Activity task, a typical scenario is launching a third-party URL scheme.

Proposal

Maybe we should add FLAG_ACTIVITY_NEW_TASK to Intent when using LaunchMode.externalApplication?

source code

bruce3x commented 3 weeks ago

I try to add FLAG_ACTIVITY_NEW_TASK when launch external Intent in my fork version https://github.com/bruce3x/packages/commit/02dc6d0311f6b6ef243ac733d181cd4ace15c1dd

  ActivityInfo activityInfo = launchIntent.resolveActivityInfo(activity.getPackageManager(), 0);

  boolean isOurApp =
      activityInfo != null && activity.getPackageName().equals(activityInfo.packageName);
  if (!isOurApp) {
    launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  }

This change is sufficient for our needs. However, for the Flutter framework, a more generalized solution might be necessary to assist different developers.

bruce3x commented 2 weeks ago

Hi, do you have any suggestions? Maybe I can submit a PR. @gmackall @huycozy

stuartmorgan commented 2 weeks ago

Can you explain at a high level what your use case is here? I.e., what is the change in behavior, in terms of user experience, that you are trying to effect with this flag?