Skip to content
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

C: 2 - Refactor main activity start activities into Navigator #13

Closed
vestrel00 opened this issue Jul 24, 2017 · 6 comments
Closed

C: 2 - Refactor main activity start activities into Navigator #13

vestrel00 opened this issue Jul 24, 2017 · 6 comments
Assignees
Labels
Milestone

Comments

@vestrel00
Copy link
Owner

Move all start activity code in main activity into the Navigator class.

@vestrel00 vestrel00 added this to the C: mvp milestone Jul 24, 2017
@vestrel00 vestrel00 self-assigned this Jul 24, 2017
vestrel00 added a commit that referenced this issue Jul 24, 2017
…ity-start-activities-into-navigator

Moved all start activity code in main activity into the Navigator class. Closes #13
@Rainer-Lang
Copy link
Contributor

@vestrel00 I think for better understanding you could make an example with passing parameter to the navigator (for the starting activity). This is only a suggestion, and really not needed.
I really like your blogs on Medium and your example here on Github. Great job!

@Rainer-Lang
Copy link
Contributor

What do you think about this: (It is a static method in the activity itself)

public static void start(@NonNull Context ctx, @NonNull String parameter) {
    Intent intent = new Intent(ctx, StartThisActivity.class);
    intent.putExtra(EXTRA_PARAMETER, parameter);
    ctx.startActivity(intent);
}

@vestrel00
Copy link
Owner Author

@Rainer-Lang you are correct. I did not include such an example because it was not needed. However, I should at least mention it in the blog in the refactor navigator section.

Here is an example in the larger project: https://github.com/vestrel00/business-search-app-java/blob/develop/presentation-java-android-mvp/src/main/java/com/vestrel00/business/search/presentation/java/android/mvp/ui/business/details/BusinessDetailsActivity.java#L35

Thanks.

@Rainer-Lang
Copy link
Contributor

@vestrel00 Why are you using an Intent (as return) and not starting the activity right now (like in my example)?

@vestrel00
Copy link
Owner Author

@Rainer-Lang good question. The reason is that sometimes there are certain flags that we want to add into the Intent. A good example are flags that modify the behavior of the tasks and back stack. An example for when this comes in handy is when we need to start an activity in singleTop launchMode with the flag FLAG_ACTIVITY_CLEAR_TOP from a DeepLinkActivity. We wouldn't declare this launchMode and intent flags and affinities in the AndroidManifest because we only want that behavior coming from our DeepLinkActivity.

We could add these flags as parameters to the static method, but that would involve adding more parameters or overloaded methods. We choose to limit the responsibility of the static method to adding extra parameters and other things (like intent flags / affinities) be handled in the Navigator. This gives us extra flexibility on what we do with the Intent.

With all that said, it still just comes down to preference. Either way is fine.

@Rainer-Lang
Copy link
Contributor

@vestrel00 Thanks for clarifying. I'm also considering using the lib "Dart and Henson".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants