user interface in an Activity” • Used to compose a modular UI • One fragment may only be a piece of what the user sees on screen • Receive lifecycle callbacks to allow state saving
user interface in an Activity” • Used to compose a modular UI • One fragment may only be a piece of what the user sees on screen • Receive lifecycle callbacks to allow state saving • Meant to be reusable across different activities
the fragment by acquiring a reference… • ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment); • In some cases, you might need a fragment to share events with the activity…
the fragment by acquiring a reference… • ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment); • In some cases, you might need a fragment to share events with the activity… • Create Interface that your Activity implements
the fragment by acquiring a reference… • ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment); • In some cases, you might need a fragment to share events with the activity… • Create Interface that your Activity implements • Activity should coordinate communication between fragments
Fragment A and B • Activity A has logic tied to Fragment B • Activity B (containing Fragment B) should be used on phone-sized devices • Activity B has logic tied to Fragment B
user interface in an Activity” • Used to compose a modular UI • One fragment may only be a piece of what the user sees on screen • Receive lifecycle callbacks to allow state saving • Meant to be reusable across different activities
user interface in an Activity” • Used to compose a modular UI • One view may only be a piece of what the user sees on screen • Receive lifecycle callbacks to allow state saving • Meant to be reusable across different activities
back stack gives full control of API you’ll be using for, potentially, years • You know when events are going to happen • Fragment API history riddled with unpredictable callbacks
back stack gives full control of API you’ll be using for, potentially, years • You know when events are going to happen • Fragment API history riddled with unpredictable callbacks • IllegalStateException says Hi
back stack gives full control of API you’ll be using for, potentially, years • You know when events are going to happen • Fragment API history riddled with unpredictable callbacks • IllegalStateException says Hi • As with any in-house API, updates are under your control
Set of back stack objects • Activity attaches to specialized Presenter-type class which controls navigation • Activity handles creating views defined in BackStack items • Also in charge of animating views in/out
• Similar to Fragments in that they are wrappers around View inflation • Callbacks for permission results/activity result/etc. • Highly streamlined lifecycle
“ViewController”s • Also gives full control over back stack history • Gives easy access to “scopes” to assist in dependency injection • Customizable transitions • Annotation-based