Croutons not showing properly - CroutonQueue somehow stuck?

714 Views Asked by At

I'm facing a serious problem with the Croutons Notification Library, When i quickly switch my activites, sometimes (very often indeed) croutons for updates, like missing credentials, or "insert date first" are not shown anymore, and so the users stay without any info, what's the problem.

For instance also the simple usecase: Login To Application, Logout,

try to re-login but with false credentials, doesnt show a crouton anymore.

I tried: Courton.clearAllNotifcations() in inPause(), and additionally, Crouton.clearCroutonsForActivity(this) too in onPause(),

to maybe solve the Problem, but it didn't.

I also debugged in the CroutonLibrary and the problem seems to be, a Crouton gets added to queue, the the activity gets finished, the something finishes (like aSyncTask showing a crouton in onPostExecute(), this one gets added to the queue again, and then the queue is stuck.

Also.clearAllNotifications (which actually clears the queue) doesn't work, because the courton (asynctask finishes after acitvity.finish()) gets added afterwards, and the problem persists.

also tried:

   @Override
    protected void onDestroy() {
         Crouton.clearCroutonsForActivity(this);
         Crouton.cancelAllCroutons();
         super.onDestroy();
     }

knwon issue: https://github.com/keyboardsurfer/Crouton/issues/24 but didn't work too...

Thankful for any advice! :)

2

There are 2 best solutions below

0
On BEST ANSWER

thx @keyboardsurfer for the explanation...

adding... and extracting the AsyncTask to a member variable...

@Override
    protected void onPause() {
        Crouton.clearCroutonsForActivity(this);
        if (loadTasksTask != null) {
            loadTasksTask.cancel(true);
        }
        super.onPause();
    }

fixed the issue! :) thx a lot :)

0
On

You have found the correct issue on Crouton and the part of the code that is responsible for producing the issue.

In your case it correlates with the AsyncTask which is still running when your Activity actually should have been destroyed already. It's generally a good thing to move long running behavior out of user facing components, i.e. using a service layer.

Until then canceling the AsyncTask should do the trick.