Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Fragments does not match bottom navigation view icon when app gets recreated  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm doing an app that is using fragments with a bottom navigation view and I've encountered a quite troublesome issue. For instance, let's say that I'm on the setting page which is the third fragment which is linked to the third icon of the bottom navigation view.

When I exit my app and use another one which means that my app is in the background (for instance I'm watching a video on youtube). When I go back to my app after a while it gets recreated, I notice that the fragment displayed will not be the one I was on when exiting the app (the first fragment gets displayed) but the active icon on the bottom navigation view is the still the one I was on before leaving the app (setting icon).

I was wondering if there's was a way to make sure that my fragment would be correctly attached to its bottom navigation icon if ever the application get recreated.

here's my code for displaying and linking the fragments to the botom navigation view:

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rachid,

When you go to the background(minimize app or switch to another app), your activity will stop, so when you come back it always restart your activity according to android activity life cycle. Moreover in you have set fragment 1 (CustomFragment) commit as default.  

"
fm.beginTransaction().add(R.id.main_container, fragment4, "4").hide(fragment4).commit();
   fm.beginTransaction().add(R.id.main_container, fragment3, "3").hide(fragment3).commit();
   fm.beginTransaction().add(R.id.main_container, fragment2, "2").hide(fragment2).commit();
   fm.beginTransaction().add(R.id.main_container,fragment1, "1").commit();

"    
 
Rachid Insa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nd Roid wrote:Hi Rachid,

When you go to the background(minimize app or switch to another app), your activity will stop, so when you come back it always restart your activity according to android activity life cycle. Moreover in you have set fragment 1 (CustomFragment) commit as default.  

"
fm.beginTransaction().add(R.id.main_container, fragment4, "4").hide(fragment4).commit();
   fm.beginTransaction().add(R.id.main_container, fragment3, "3").hide(fragment3).commit();
   fm.beginTransaction().add(R.id.main_container, fragment2, "2").hide(fragment2).commit();
   fm.beginTransaction().add(R.id.main_container,fragment1, "1").commit();

"    




Thanks I was ble to resolve the issue!
 
Paper beats rock. Scissors beats tiny ad.
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!