Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@thanhdatvo
Copy link
Contributor

Description

we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag

Similar to react native Link.openUrl() : https://github.com/facebook/react-native/blob/3b6f6ca4d5fcee6f1bc6d6242e3e2ef136e4d546/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java#L97

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@thanhdatvo
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@thanhdatvo thanhdatvo changed the title add logic code android_intent: we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag Aug 13, 2019
@thanhdatvo thanhdatvo changed the title android_intent: we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag [android_intent] we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag Aug 13, 2019
@thanhdatvo thanhdatvo changed the title [android_intent] we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag [android_intent] if we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag Aug 13, 2019
@ened
Copy link
Contributor

ened commented Aug 15, 2019

@datvo0110 please bump version & add change log entry.

I'm wondering if this should be done explicitly via an extra enum flag in the AndroidIntent class.
Can you think of other flags that may be of interest in the future?

I can think of those, for example:

Intent.FLAG_ACTIVITY_NEW_TASK
Intent.FLAG_ACTIVITY_NO_HISTORY
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
Intent.FLAG_GRANT_READ_URI_PERMISSION

@thanhdatvo thanhdatvo requested a review from mklim as a code owner August 16, 2019 04:01
@thanhdatvo
Copy link
Contributor Author

@ened I have bumped version from 0.3.2 to 0.3.3 & add change log entry. Is this ok?

Copy link
Contributor

@mklim mklim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

I'm wondering if this should be done explicitly via an extra enum flag in the AndroidIntent class.
Can you think of other flags that may be of interest in the future?

I agree. I think the behavior in this PR makes sense in most cases, but not every app would necessarily want external activities to behave in this way. I filed flutter/flutter#38701 to track the feature in general.

I'm following the initial PR review policy. This PR isn't trivial to review so I'm labeling it with "backlog." We'll prioritize according to the issue's priority.

Relevant issues:
flutter/flutter#38701

@mklim mklim added the backlog label Aug 16, 2019
@ened
Copy link
Contributor

ened commented Aug 16, 2019

@datvo0110 let’s rewrite this a bit and add the flags argument instead of having app behavior done implicitly using the package name only. L

Are you up for changing adding and implementing the ‘flags’ parameter?

@thanhdatvo
Copy link
Contributor Author

thanhdatvo commented Aug 17, 2019 via email

@thanhdatvo
Copy link
Contributor Author

thanhdatvo commented Aug 20, 2019 via email

@thanhdatvo thanhdatvo changed the title [android_intent] if we are launching to a different package we need to set the FLAG_ACTIVITY_NEW_TASK flag [android_intent] add flags parameter Aug 20, 2019
Copy link
Contributor

@ened ened left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, nice.
There is some potential to optimise the code (calculate the flags integer in Dart and send that to the platform, instead of a list of strings which needs separate handling).
Also, please add unit and integration tests for this.

}
}

private int convertFlag(String flag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR converts the flags from String to integer using this method.
A better method is to let the Dart side know about the flag names & values and simply push the flag through. You can create a new Flags.dart (or similar) and fill in the constants from https://developer.android.com/reference/android/content/Intent (All the constants from FLAG_).

Please follow the hex numbering (0x00400000) and keep the order as it is listed on the documentation page.

}
}

private int convertFlags(ArrayList<String> flags) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said above, this logic should be done in the Dart side.

/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
2D5378261FAA1A9400D5DBA9 /* flutter_assets in Resources */ = {isa = PBXBuildFile; fileRef = 2D5378251FAA1A9400D5DBA9 /* flutter_assets */; };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in here relate to the iOS example. If possible, please remove them from the commit.

final AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: Uri.encodeFull('https://flutter.io'),
flags: flags);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • please add a , to before the parentheses end
  • this now becomes simpler as you can do the bit operation in Dart

RaisedButton(
child: const Text(
'Tap here to open link in browser in a seperated window.'),
onPressed: _openLinkInDefaultBrowserInSeperatedWindow,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like a close-to-reality example like this one, however I would name it more accurate ("Start Activity in New Task"). What other ways could we use in the example to demonstrate the functionality?

@thanhdatvo thanhdatvo force-pushed the feature/android_intent_open_app branch from 59a9413 to bd5a534 Compare August 22, 2019 10:42
@thanhdatvo
Copy link
Contributor Author

thanhdatvo commented Aug 22, 2019

@ened I already
-- brought logic from java to dart, add flag list
-- added test case
-- updated example
sorry because I tried to remove packages/android_intent/example/ios/Runner.xcodeproj/project.pbxproj so I have to reset to the old commit, now it contained some unrelated file @@

@thanhdatvo
Copy link
Contributor Author

@ened
sorry, the commit is like a mess now
i have already prepared a new clean commit #2000
let's switch to the other commit to continue

@ened
Copy link
Contributor

ened commented Aug 22, 2019

@datvo0110 ok let's close this one and move to #2000.

@thanhdatvo
Copy link
Contributor Author

Hi @ened, @mklim please help me review #2000

@thanhdatvo thanhdatvo closed this Aug 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants