Skip to content

GitEliteNovice/BackStack_BottomNavigation

Repository files navigation

Bottomnavlibrary v1.01

API Android Arsenal Twitter URL Maintenance Ask Me Anything ! PRs Welcome ForTheBadge built-with-love

How this is helpful for you?

With the help of this library , handling fragment will be Piece of cake for you. This library helps you to keeps history of previous tabs so that when the current tab's stack is exhausted the system back button will navigate to the previously selected tab. If you want to switch between fragments with botttomnavigation view, without losing fragments state and along with if you want to maintain backstack of fragments. Then this library is for you.

**Note:-This example handles backstack and even app restores when after killed by Android System, all backstacks are preserved.

If you want to say thanks or want to share how much you like my efforts, then you can share it with me with Say Thanks!

Webp net-resizeimage Webp net-resizeimage (1) Webp net-resizeimage (2)

Includle this library in your project

For Gradle

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
         implementation 'com.github.GitEliteNovice:BackStack_BottomNavigation:v1.01'
}

For Maven

       <repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Step 2. Add the dependency

<dependency>
   <groupId>com.github.GitEliteNovice</groupId>
    <artifactId>BackStack_BottomNavigation</artifactId>
    <version>v1.01</version>
</dependency>

For implementation

Make instance of Library like this

 fragmentStackNew= com.aryan.bottomnavlibrary.FragmentStackNew.Builder()
                     .bottomMaxCount(3)                      // bottom tabs you have 
                     .conatiner_id(R.id.frag_container)     // container id when you want add fragments	  	         
		 .lastFragmentToStay(HomeFragment::class.java).   // last fragment to reach when all fragment removed from backstack
                     .build(this)            

 fragmentStackNew.updateFrag(HomeFragment::class.java,null).       // add fragment to show 

If you want to send extra data to fragment, you can do something like this

 bundle= Bundle()
 bundle.putString("Name","Aryan")
 bundle.putInt("Age",27)
   	    
 fragmentStackNew.updateFrag(HomeFragment::class.java,bundle).    // send extra data to fragment

If you want to handle state even when the activity kills by andoid os

 override fun onSaveInstanceState(outState: Bundle) {
     var outStatenew=  fragmentStackNew.setOutstatebundle(outState).    // add oustate bundle to library instance
      super.onSaveInstanceState(outStatenew)
   }

Inside onCreate method, do something like this

if (savedInstanceState==null){

 fragmentStackNew= com.aryan.bottomnavlibrary.FragmentStackNew.Builder()
                       .bottomMaxCount(3)
                       .conatiner_id(R.id.frag_container).
                        lastFragmentToStay(HomeFragment::class.java)
                         .build(this)

       bundle.putString("Name","Aryan")
       bundle.putInt("Age",27)
  
   fragmentStackNew.updateFrag(HomeFragment::class.java,bundle)
  
   }
else
  {

fragmentStackNew= com.aryan.bottomnavlibrary.FragmentStackNew.Builder()
    .bottomMaxCount(3)
    .conatiner_id(R.id.frag_container).
    lastFragmentToStay(HomeFragment::class.java)
    .build(this)
         
fragmentStackNew.savedInstanceState(savedInstanceState)

   }

This example includes following things

  • BottomNavLibrary
  • BottomNavigationView


Android library to keeps a history of previous tabs

Built with ❤︎ by Aryan Dhankar.

Connect With Me

Aryan Dhankar (Elite Novice) I love making new friends, please feel free to connect with me.

Connect me on Google+ Connect me on Facebook Connect me on LinkedIn

Question / Contact Me

Please feel free to ping me at [email protected].