Comments (8)
In what order do you call navigation method?
This order goForward, switchTo means for a navigator "go to a lock screen and then switch screens there". In that case NavigationException is expected because a lock screen can't switch screens. So an order should be opposite - switchTo, goForward. Or you can use ScreenResult if you want to switch screens after an user returns from a lock screen.
from alligator.
Yes I know but I cannot switch that order because of the implementation of the app.
The thing is:
1 - Open activity that will load a fragment with switchTo().
2 - While the activity is being opened, on the "onStart()" method, a goForward() command is executed to navigate to a LockActivity because you have to set a pincode to access the app.
3 - Before the "goForward()" is executed, the first activity is not stopped yet and the "switchTo()" command is added to the queue.
4 - Alligator executes the goForward() to the LockActivity and then when the navigation context is set, the pending switchTo() command is executed without a ScreenSwitcher added.
In my concrete implementation, as the navigation to the LockActivity is done on an external lifecycle callback, I cannot know if the LockActivity is pending to be opened from any activity. If I could access the navigation queue (at least read only), I could check if there is a goForward() pending before adding the switchTo() command.
from alligator.
Still don't understand where and when do you call switchTo().
from alligator.
I call it after onStart(), but the first activity creation lifecycle is still running when I am navigating to the LockActivity, so switchTo() is called after goForward().
from alligator.
In my opinion the best solution would be rethink how navigation to a lock screen is called. The order of navigation method calls is crucial here. It is hard to give a concrete advice because I don't know how your implementation looks like.
If I could access the navigation queue (at least read only), I could check if there is a goForward() pending before adding the switchTo() command.
I'm not sure that giving a direct access to the navigation queue is a good idea. It is supposed to be implementation detail but not a pulic api.
from alligator.
I thought about the issue some more and decided that these methods should be added to Navigator
:
boolean canExecuteCommandImmediately()
- returns true if a navigator can execute a command immediately (NavigationContext is bound and a queue is empty).boolean hasPendingCommands()
- returns true if a navigator has pending commands (a queue is not empty).
You can use it like that:
@Override
protected void onStart() {
super.onStart();
if (mScreenSwitcher.getCurrentFragment() == null && !mNavigator.hasPendingCommands()) {
mNavigator.switchTo(new SomeScreen());
}
}
Now this change is in the develop branch. Take it from jitpack.io. Give me to know if it is helpful for you. Then I will make a release.
from alligator.
That's a more robust solution! Yes is absolutely helpful, many thanks.
This library is the best solution for android navigation I've ever seen, sorry if I bother you too much with my issues but I really want to contribute to it :)
from alligator.
I am very glad. Thank you for helping to make Alligator better.
Version 2.1.0 is ready!
from alligator.
Related Issues (20)
- Question: How to get the activity result from a fragment? HOT 1
- Handle result if activity is destroyed HOT 10
- Nested fragment ScreenSwitcher HOT 1
- Integration with AAC Navigator HOT 1
- Fragment BackStack Handling HOT 4
- Navigation tree HOT 2
- In which case getScreen can return null ? HOT 5
- Kotlin HOT 2
- Translucent activity not finished with result HOT 4
- It makes sense to have a method returning the current screen (and maybe the activity/fragment) on AndroidNavigator? HOT 1
- AndroidX HOT 3
- Can an Instagram Like navigation be done with this Library HOT 2
- Cannot generate Class HOT 1
- Help Needed HOT 8
- screenResolver.getScreen() returns null HOT 4
- [Improvement] Make a new navigator method to keep already loaded Fragments. HOT 1
- Pop fragments/screens if HOT 2
- Fragments and ViewPager HOT 3
- Passing ScreenResult from one fragment to another fragment HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alligator.