mikepenz/Android-ActionItemBadge

Cant populate items from firebase to show listView count to the Badge.

Closed this issue · 6 comments

The badge doesnt populate when receiving the ListView item from firebase console. It works only when it come in the foreground, It doesnt update when we fire a new ListView item or the app is in Background or Killed?

it is up to you to update the badge with the provided API in the toolbar.
also make sure you do this on the UI thread

I think it's not working with the FCM service onMessageReceived() method. It's actually not updating. Any ideas on that?

I would believe it's not on the UI thread.

try moving the update of the UI to the UI thread. and see what happens

Look at the code @mikepenz
The app is updating the listview count just after i minimize the app and start again.
I have uploaded these
App icon is also updated

        database = FirebaseDatabase.getInstance();
        myRef = database.getReference("Users");

        listView = (ListView) findViewById(R.id.listView);
        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, 
        android.R.layout.simple_list_item_1,mUsername);
        listView.setAdapter(arrayAdapter);
        int count = listView.getAdapter().getCount();
        String value = Integer.toString(count);
        Log.v("Expected: 3", value);

    @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            final MenuItem menuItem = menu.findItem(R.id.action_send);

        View actionView = MenuItemCompat.getActionView(menuItem);
        textItemCount = (TextView) 
        actionView.findViewById(R.id.action_send);

         mbadgeCount = 
         Integer.parseInt(String.valueOf(listView.getAdapter().getCount()));
        if(mBadgeCount != 0) {
            ActionItemBadge.update(this, menu.findItem(R.id.action_send), FontAwesome.Icon.faw_file_o, ActionItemBadge.BadgeStyles.RED, mBadgeCount);
            ShortcutBadger.applyCount(this, mBadgeCount);
        }
        else {
            ActionItemBadge.update(this, menu.findItem(R.id.action_send), FontAwesome.Icon.faw_file_o, ActionItemBadge.BadgeStyles.RED, countNull);
            // ShortcutBadger.removeCount(MainActivity.this);
        }

        actionView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onOptionsItemSelected(menuItem);
            }
        });

        return true;
    }

Please report back if this issue is still relevant