Croutons not showing from time to time
Asked Answered
L

1

5

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?

Lymphatic answered 26/2, 2014 at 10:13 Comment(2)
Are you using the workaround described here?Pommard
I found out Croutons stopped appearing when I left a Fragment while a Crouton was currently shown. Calling Crouton.cancelAllCroutons() in onPause() helped.Lymphatic
L
9

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

Lymphatic answered 3/7, 2014 at 15:59 Comment(2)
This helped me a lot - I thought it was a mutithreading problem, but it was just that I was showing a Crouton during a Fragment transition and after that no more croutons worked. Calling cancelAllCroutons in onPause of my fragment before I leave the fragment fixed this for me. Thanks!!!Papism
indeed it clears the message Queue for new Croutons objects to be addedd and processed. Stale ones might be choking the Q. Awesome answerLowney

© 2022 - 2024 — McMap. All rights reserved.