Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designing effective navigation in Android

Designing effective navigation in Android

From principles to implementation, the new Navigation Architecture Component helps to design the interactions that allow users to navigate across, into, and back out from the different pieces of content within the app.

Renaud will explore the basics and then dive into specific use cases such as deep-linking, manipulating the back-stack or even providing safe arguments.

Renaud MATHIEU

February 22, 2019
Tweet

More Decks by Renaud MATHIEU

Other Decks in Programming

Transcript

  1. The act of moving between screens of an app to

    complete tasks. 
 Navigation
  2. Lateral Navigation Component Use for # destinations Navigation drawer Top-level

    destinations 5+ Bottom navigation bar Top-level destinations 2-5 Tabs Any level of hierarchy 2+
  3. Navigation is a complex task that is usually overlooked by

    developers. Pass data between screens Deep linking Transitions Up and back actions Navigation UI patterns Fragment transactions
  4. Navigation component basics • Fixed start destination • Navigation state

    should be represented via a stack of destinations • The Up button never exits your app • Up and Back are identical within your app's task (stack) • Deep linking and navigating to a destination should yield the same stack
  5. Create a navigation graph <?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/navigation_authentication" app:startDestination=“@id/splashFragment"> <fragment android:id="@+id/splashFragment" android:name="com.alephom.android.presentation.authentication.splash.SplashFragment" android:label="SplashFragment" tools:layout="@layout/fragment_splash"> <action android:id="@+id/action_splashFragment_to_loginFragment" app:destination="@id/logInFragment"/> <action android:id="@+id/action_splashFragment_to_mainActivity" app:destination="@id/mainActivity" /> </fragment> … </navigation>
  6. Navigation is a complex task that is usually overlooked by

    developers. Pass data between screens Deep linking Transitions Up and back actions Navigation UI patterns Fragment transactions
  7. Migrate to the Navigation Architecture Component step by step. Activity

    A Navigation Graph A Activity B Navigation Graph B
  8. Migrate to the Navigation Architecture Component step by step. Activity

    A Navigation Graph A Activity B Navigation Graph B
  9. Pass data between destinations private val fragmentArgs by navArgs<SearchProductsFragmentArgs>() //

    later in code, access properties from args storeId = fragmentArgs.storeId DESTINATION
  10. Listen for navigation events. findNavController(R.id.hostFragment).addOnDestinationChangedListener { _, destination, _ ->

    KeyboardUtils.hideSoftKeyboard(this, window.decorView) when (destination.id) { R.id.profileFragment, R.id.purchasesFragment, R.id.homeFragment -> showBottomNavigation(true) else -> showBottomNavigation(false) } }
  11. Navigation is a complex task that is usually overlooked by

    developers. Pass data between screens Deep linking Transitions Up and back actions Navigation UI patterns Fragment transactions
  12. Keep it simple Pass data between screens Deep linking Transitions

    Up and back actions Navigation UI patterns Fragment transactions
  13. Intents override fun onActivityResult( requestCode: Int, resultCode: Int, data: Intent?

    ) { super.onActivityResult(requestCode, resultCode, data) if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { // DO SOMETHING } } … startActivityForResult(intent, REQUEST_CODE)