Giter VIP home page Giter VIP logo

Comments (8)

aartikov avatar aartikov commented on May 26, 2024

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.

emanzanoaxa avatar emanzanoaxa commented on May 26, 2024

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.

aartikov avatar aartikov commented on May 26, 2024

Still don't understand where and when do you call switchTo().

from alligator.

emanzanoaxa avatar emanzanoaxa commented on May 26, 2024

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.

aartikov avatar aartikov commented on May 26, 2024

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.

aartikov avatar aartikov commented on May 26, 2024

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.

emanzanoaxa avatar emanzanoaxa commented on May 26, 2024

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.

aartikov avatar aartikov commented on May 26, 2024

I am very glad. Thank you for helping to make Alligator better.
Version 2.1.0 is ready!

from alligator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.