直到重新创建活动,通知徽章才会自行消失

时间:2019-09-10 05:21:23

标签: android firebase notifications navigationbar badge

我有一个主要活动,该活动仅包含底部导航栏。底部导航栏中存在的项目用于在主活动中切换框架布局中的不同片段。根据每个片段中的特定条件,通知徽章会出现在其相关项目上,以指示新的东西或通知。当用户输入片段并返回到上一个片段时,buttom导航中的通知徽章不会消失。

我尝试在单击每个片段底部导航项时重新创建活动,但是它不起作用。通知徽章消失的唯一方法是停止应用程序并再次将其重新打开

带有代码的帖子,这是我将徽章添加到底部导航栏的示例之一。

在进行了几项研究之后,我一直在为此苦苦挣扎一段时间。任何帮助将不胜感激

谢谢

    navigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {


            Fragment selectedFragment = null;
            switch (item.getItemId()) {
                case R.id.Services:
                    selectedFragment = new services_fragment();
                    break;
                case R.id.my_task_post_view:
                    selectedFragment = new my_posts_fragment();
                    break;
                case R.id.Search:

                    selectedFragment = new search_list_fragment();
                    break;
                case R.id.Message:
                    selectedFragment = new Message_fragment();
                    break;

                case R.id.Account:
                    selectedFragment = new Account_fragment();
                    break;
            }

            onResume();

            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                    selectedFragment).commit();

            return true;
        }
    });


 @Override
 protected void onResume() {
    super.onResume();

    onStart();


    // check if there is any message notification
    messageBadge();


    // check if the account needs to have a notification badge\
    accountBadge();
    postBadge();
    bidsBadge();
    tasksBadge();
    myCompletedTaskBadge();


}


private void accountBadge() {

    notification_counter.child(current_user_id).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                if (dataSnapshot.child("status").getValue().toString().equalsIgnoreCase("false")) {
                    BottomNavigationMenuView menuView = (BottomNavigationMenuView) navigationView.getChildAt(0);
                    final BottomNavigationItemView itemView = (BottomNavigationItemView) menuView.getChildAt(4);
                    notification_badge_account = LayoutInflater.from(Services.this).inflate(R.layout.view_notification_badge_account, menuView, false);


                    // TEXTVIEW
                    if (notification_badge_account.getParent() != null) {
                        ((ViewGroup) notification_badge_account.getParent()).removeView(notification_badge_account); // <- fix
                    }
                    itemView.addView(notification_badge_account); //  <==========  ERROR IN THIS LINE DURING 2ND RUN
                }
            }
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });


}

我真正想要的是,如果用户单击底部导航栏中的不同项目,则通知条件应消失,而无需停止应用程序并再次运行它。它认为由所有片段组成的主要活动没有得到刷新,因此正面临这种行为

0 个答案:

没有答案