New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/new task #1195
Merged
MateusAndrade
merged 3 commits into
react-native-share:main
from
JohnWilliamForcier-Spiria:feature/new_task
May 5, 2022
Merged
Feature/new task #1195
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
openNewIntent
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason it's called isNewTask is because it's specifically using the flag that forces the system to put any activity started as a result of the Intent in a new task, I was just reading up on it in response to seeing this PR:
https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK - it's clearly called "new task" and the whole tasks / back stack / user navigation flow uses "Task" as a term of art that is related to - but not the same as "new intent".
All of our shares are new Intents, but this makes the new Intent also put the new Activity in it's own separate history backstack which alters back behavior in specific ways
https://developer.android.com/guide/components/activities/tasks-and-back-stack#IntentFlagsForTasks
I think it's named fine. I guess what I'm having trouble with is deciding if this should actually be the default or not! Honestly it seems like it should be the default now that I read about it deeply. When submitter @SpiriaJWF says "app", in Android terms what that means is not what's in your APK, it means "one task with a backstack of Activities" - that single task with it's backstack is what shows up in the recents switcher if I understand correctly? So this isNewTask behavior means that the Activity started as a result of a share will be a fresh "app" in the recents, running on it's own with it's own independent history now.
I also noticed we set FLAG_ACTIVITY_NO_HISTORY which will interact with this as well, maybe not in a great way
react-native-share/android/src/main/java/cl/json/social/ShareIntent.java
Line 271 in f9120fe
By setting that currently, it means that after the share, if the user hits the home button or uses recents to do anything outside of the activity opened for the share, the activity just goes poof, which is odd. And it might be the root of why we don't get share results, according to the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this may only really be visible as a "mixed" (shared Activity as top item in your app's backstack inside the same task) app experience if the app wasn't already started in it's own Task prior to the share. Concretely, if Whatsapp was not open (as if! it's always open, but kill it for testing), then if you share to whatsapp you may see whatsapp pop up as the top activity on your mobile. Not sure if that example is perfect because whatsapp may define in it's Manifest that it always gets a separate task (it should really), but the same test can be tried with different share targets and I bet at least some of them will open up inside your app. Maybe @SpiriaJWF has a concrete example of an app that ends up in the react-native app's task as top activity on backstack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch @mikehardy! I think I made confusion with the Intent + Tasks here.
Also, as you mentioned it can be annoying to have the behavior of "destroying" the app that was open when the user presses the back button. What do you think if you give at try changing:
To a more "user-friendly" behavior using
FLAG_ACTIVITY_NEW_TASK
? I didn't have time to read properly about the differences between these two, but it might be a good idea to give it a try. 😄