2017-07-30 28 views
0

我正在使用底部導航視圖,並在其中一個選項中顯示Firebase數據和CardView。當活動返回時不更新Firebase數據 - 底部導航視圖

但是,當我退出此活動並返回時,無論是使用設備後退按鈕還是使用活動箭頭,它都不起作用。不顯示任何東西。

什麼可能是錯的?

打印: 前: enter image description here

後: enter image description here

代碼底部導航視圖:

BottomNavigationView bottomNavigationView =(BottomNavigationView) findViewById(R.id.bottomNavView_Bar); 
     BottomNavigationViewHelper.disableShiftMode(bottomNavigationView); 
     Menu menu = bottomNavigationView.getMenu(); 
     MenuItem menuItem = menu.getItem(0); 
     menuItem.setChecked(true); 

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

       switch (item.getItemId()){ 

        case R.id.ic_home: 

         break; 

        case R.id.ic_explore: 

         Intent intentExplore = new Intent(HomeActivity.this, ExploreActivity.class); 
         intentExplore.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(intentExplore); 
         break; 

        case R.id.ic_calendar: 
         Intent intentAgenda = new Intent(HomeActivity.this, AgendamentoActivity.class); 
         intentAgenda.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(intentAgenda); 
         break; 

        case R.id.ic_person: 
         Intent intentuser = new Intent(HomeActivity.this, OpcoesUsuarioActivity.class); 
         intentuser.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
         startActivity(intentuser); 
         break; 

       } 

       return false; 
      } 
     }); 

注:在活動測試,而底部的導航或SlidingTabs,它的工作原理一般。

回答

0

那麼你正在使用關於BottomNavigationView的錯誤方法,你需要使用Fragment而不是Activities檢查this。關於你的問題,當你點擊任何你放置活動的項目時,意味着活動仍然在堆疊但不可見,當點擊返回時你剛剛完成當前活動並回到最後一個調用onResume方法onCreate沒有被調用,所以請將RecyclerView工作放在您的onResume方法中,或者在離開活動時調用finish()

相關問題