Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlidingUpPanelLayout won't collapse on resume after OS kill my activity

I am using the latest version (3.0) of the SlidingUpPanelLayout library. Periodically the Android OS would kill my Activity if it's running in the background (exit by pressing Home instead of Back). If that happens, and the panel was expanded when the user last used the app, then the panel would still be expanded when it's created but all the content inside would be gone. Basically a blank screen.

In this scenario, I actually want to reset the activity to it's initial state (open after a full exit), which is collapsed. But I can't get that to work. In the layout xml, I am setting the initial state to collapsed.

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="48dp"
    sothree:umanoShadowHeight="4dp"
    sothree:umanoInitialState="collapsed" >

I also placed this line

slidingUpPanelLayout.setPanelState(PanelState.COLLAPSED);

at a few places in onCreate(), but panel is not collapsing. I printed the panel state before and after each collapse attempt and found that the panelState is actually set to collapsed even before the first collapse attempt, even though it clearly isn't collapsed.

So is this a bug in the library, or am I doing something wrong.

Thanks for your help.

like image 707
Kent Avatar asked Feb 19 '15 20:02

Kent


1 Answers

You need to override onResume event, and then call the collapse action. The code below should do the work:

@Override
protected void onResume() {
    super.onResume();
    slidingUpPanelLayout.setPanelState(PanelState.COLLAPSED);
}
like image 67
Abdullah Erdemir Avatar answered Sep 22 '22 20:09

Abdullah Erdemir