Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Croutons not showing from time to time

I have the official Navigation Drawer in my app. Clicking items in the drawer opens new Fragments in the content part of the screen. Every Fragment contains FrameLayout with the same id which is used for displaying a Crouton.

Basic use is that an infinite Crouton is shown when user clicks refresh button in Action Bar (notifying about ongoing refresh). After refresh is finished, another crouton is shown (replacing the old one). In some cases Croutons are shown even right after a screen is entered (and replaced when refresh is triggered).

The issue I'm experiencing is a bit difficult to describe. Some Croutons are just not showing from time to time. It usually happens when I switch between screens (the initial Crouton is not shown or the Crouton is not shown when I press refresh button for the first time on that screen - however, it is displayed when refresh finishes and when I press refresh button afterwards).

So it is pretty unpredictable. There even are cases, when the screen doesn't show the Crouton at all until I switch to another screen and back.

For displaying Croutons I use this in every Framgnet's layout:

<FrameLayout
    android:id="@+id/crouton_view"
    android:layout_width="match_parent"
    android:layout_height="@dimen/crouton_height"
    android:layout_alignParentTop="true" />

In code I have CroutonBuilder class with following methods:

public static Crouton getNewLastUpdateCrouton(Activity activity, boolean infinite, String plateNumber) {
    String lastUpdateString = ...;
    Crouton newCrouton = Crouton.makeText(activity, lastUpdateString, CroutonBuilder.getLastUpdate(activity),
                                    R.id.crouton_view);
    if (infinite) {
        newCrouton.setConfiguration(new Configuration.Builder().setDuration(
                                        Configuration.DURATION_INFINITE).build());
    }
    return newCrouton;
}

and then just call .show() on the returned Crouton. When I debug and step through, the show() method is called but sometimes just nothing is shown.

Do you have any ideas what am I do wrong?

like image 917
Marcel Bro Avatar asked Feb 26 '14 10:02

Marcel Bro


1 Answers

I found out Croutons stopped appearing when I left a Fragment while a Crouton was currently shown. Calling Crouton.cancelAllCroutons() in onPause() helped.

like image 69
Marcel Bro Avatar answered Oct 08 '22 18:10

Marcel Bro