aurelhubert / ahbottomnavigation

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.
3.83k stars 682 forks source link

Notification is not update on menu with runnable thread #384

Closed badarshahzad closed 5 years ago

badarshahzad commented 5 years ago

Hi :wave: I am trying to test notifications on menu. I want to show notification after each 2 seconds pass. I am trying this example as I think If able to do this on thread to update notification on menu then I can do the same task while the data came back in the app. So, I simply try the below code but unfortunately its not working could you please figure what is wrong in the below code.

This only run once and set the value on notification menu 0 and after that this runnable not work after every 2 seconds.

int notificationCount  = 0;

 handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                  bottomNav.setNotification(String.valueOf(notificationCount), 1);
                  notificationCount++;
                  bottomNav.refresh();
            }
        },2000);
badarshahzad commented 5 years ago

Actually there was a problem in my code I didn't add handler post delayed in runnable that's why it was not scheduling the task again.

   Runnable runnable = new Runnable() {
        @Override
        public void run() {

                  bottomNav.setNotification(String.valueOf(notificationCount), 1);
                  notificationCount++;

                  bottomNav.refresh();
            Log.i(TAG, "run: working");

            handler.postDelayed(this, 1000);
        }
    };

Handler handler = new Handler();
handler.postDelayed(runnable, 5000);