skoumalcz / fragment-back

Tiny library for handling back in fragments.
Apache License 2.0
47 stars 11 forks source link

How does this work with priority increment/decrement #6

Closed erikswed closed 7 years ago

erikswed commented 7 years ago

Thanks for interesting lib, How does this work: We support five fragment priorities for ordering back-pressed event delivery This should cover majority of use-cases. If you need more fine control over priorities, feel free to increase or decrease priority by number constant. Just keep increment/decrement under 100.

What am I increment/decrement?

gingo commented 7 years ago

You can increase/decrease fragment priority by incrementing/decrementing in getBackPriority() method.

public int getBackPriority() {
    // little bit higher than normal priority
    return NORMAL_BACK_PRIORITY + 1;
}
erikswed commented 7 years ago

sorry I´m a noob I dont understand what is getting higher or lower , what is fragment priority?

gingo commented 7 years ago

Imagine you have 5 BackFragments in your Activity. Now when user hits hardware back button BackFragments are ordered by priority and the one with highest priority is notified about back-press at first.

erikswed commented 7 years ago

Thanks for taking your time, this was useful info. I just read about your github project from here this tutorial(you post in the comment section) http://vinsol.com/blog/2014/10/01/handling-back-button-press-inside-fragments/

It seams hard to get a handle on the currently active visible fragment. In the tutorial code above they solve it with the topmostFragment I think, does your library have similar functionality like topmostFragment detection

gingo commented 7 years ago

Sorry I missed your comment. You can simply use isResumed() method (https://developer.android.com/reference/android/app/Fragment.html#isResumed()) to detect if your fragment is currently active.