Share
Embed
Breaking Down the AndroidX Navigation Framework
Is the new Navigation Architecture Component worth investing your precisous time in? In this talk we’ll attempt to answer that by exploring its feature set and live coding examples.
In this talk we’ll cover the new Navigation Architecture Component that was announced at Google I/O 2018. We’ll explain why this is a very important change to how we should consider building Android applications going forward and go through the features of the component via live coding examples.
Jerrell Mardis
February 01, 2019
Transcript
31 slides
-
Breaking Down the AndroidX Navigation Framework Jerrell Mardis @jerrellmardis Making
Fragments Great Again Finally -
{com.jerrellmardis.fragmentsareterrible/com.jerrellmardis.fragmentsareterrible.MainActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at
android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4151) at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4121) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4196) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:192) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at androidx.fragment.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2080) at androidx.fragment.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2106) at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:683) at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:637) at com.jerrellmardis.fragmentsareterrible.MainActivity.onStop(MainActivity.kt:25) at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1432) at android.app.Activity.performStop(Activity.java:7367) at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:4143) at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:4121) at android.app.ActivityThread.handleStopActivity(ActivityThread.java:4196) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:192) at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) -
view.findViewById<View>(R.id.go_button).setOnClickListener {s fragmentManager?.beginTransaction()?.apply {s val myFrag = ErrorProneFragment() add(R.id.fragment_container, myFrag,
ErrorProneFragment::class.java.simpleName) setCustomAnimations(R.anim.blink, R.anim.blink) commit() }s }s -
view.findViewById<View>(R.id.go_button).setOnClickListener {s fragmentManager?.beginTransaction()?.apply {s val myFrag = ErrorProneFragment() add(R.id.fragment_container, myFrag,
ErrorProneFragment::class.java.simpleName) setCustomAnimations(R.anim.blink, R.anim.blink) commit() }s }s -
view.findViewById<View>(R.id.go_button).setOnClickListener {s fragmentManager?.beginTransaction()?.apply {s val myFrag = ErrorProneFragment() add(R.id.fragment_container, myFrag,
ErrorProneFragment::class.java.simpleName) setCustomAnimations(R.anim.blink, R.anim.blink) commit() }s }s -
view.findViewById<View>(R.id.go_button).setOnClickListener {s fragmentManager?.beginTransaction()?.apply {s val myFrag = ErrorProneFragment() setCustomAnimations(R.anim.blink, R.anim.blink)
add(R.id.fragment_container, myFrag, ErrorProneFragment::class.java.simpleName) commit() }s }s -
view.findViewById<View>(R.id.go_button).setOnClickListener {s fragmentManager?.beginTransaction()?.apply {s val myFrag = ErrorProneFragment() setCustomAnimations(R.anim.blink, R.anim.blink)
add(R.id.fragment_container, myFrag, ErrorProneFragment::class.java.simpleName) commit() }s }s -
…More Pain Points Fragment Transactions are error prone Animating Fragments
are difficult Managing the back-stack seems like a failure of the framework Managing Deep Links is not scalable Passing Arguments is not type-safe -
More Pain Points… Fragment Transactions are error prone Animating Fragments
are difficult Managing the back-stack seems like a failure of the framework Managing Deep Links is not scalable Passing Arguments is not type-safe -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Provides Declarative approach Manages back-stack and up/back button behavior
Reduces boilerplate code Simplifies creating Fragment animations Removes the need to write Fragment transactions Creates a type-safe way to pass Fragment arguments -
Navigation Components Graph and Nested Graphs An XML file which
describes the navigational structure -
Navigation Components NavHost NavHost is a container view which swaps
Fragments in and out -
Navigation Components Actions Connects one destination to another Defines enter/exit
behavior for destinations -
Breaking Down the AndroidX Navigation Framework Jerrell Mardis @jerrellmardis Making
Fragments Great Again Finally speakerdeck.com/jerrellmardis