In my app I have two fragments and one of them (FragmentSlidingUp) can slide up and cover the other one (FragmentContent) completely. I use this library for the sliding up https://github.com/umano/AndroidSlidingUpPanel. The problem I have is that the LiveData observers in FragmentContent are not paused when FragmentSlidingUp slides up and FragmentContent is not visible. Is there a way to set the fragment lifecycle state to Paused when the fragment is not visible so that the LiveData observers will be paused and resumed automatically when the fragment becomes visible again? Thanks.
Asked
Active
Viewed 280 times
1 Answers
1
Because this library uses a window overlay I don't think it's possible to tell in your "FragmentContent" class however what you can do is set a listener to the sliding panel and then make a call to FragmentContent when the sliding state is open. Here's the gist.
slidingPanelLayout.addPanelSlideListener(new PanelSlideListener() {
@Override
public void onPanelSlide(View panel, float slideOffset) {
Log.i(TAG, "onPanelSlide, offset " + slideOffset);
}
@Override
public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) {
Log.i(TAG, "onPanelStateChanged " + newState);
// Here's where you test the state, when open tell fragmentcontent to pause
}
});

eclipse1203
- 535
- 4
- 14
-
thanks for the gist. What I need is a way to notify the LiveData observers to stop updating when the panel is expanded, or a way to change the lifecycle state in the fragment. – user3613696 Oct 27 '17 at 18:03