10 best practices for moving to a single activity
summary
Ten concrete moves for a single-activity app: use activities only as UI entry points, share state via activity-scoped viewmodels, and extract business logic out of fragments for unit tests. Adopt the Navigation Architecture Component plus the Safe args Gradle plugin to generate type-safe directions and avoid manual fragment transactions. Use the new Fragment testing artifact (Fragment 1.1 / FragmentScenario) and mock NavController to verify navigation, employ FragmentFactory for constructor injection, and prefer multiple tasks over many activities when appropriate.
AI-written summary · about
chapters (11)
- 0:00Use Activities As Entry Points
- 0:25Share Data Between Screens
- 1:06Use the Navigation Architecture Component
- 1:58Navigate Between Destinations
- 2:36Extract Your Business Logic
- 3:01Test With Fragment Scenario
- 3:35Mock the NavController
- 4:15Inject Dependencies
- 4:32Use Multiple Tasks When Appropriate
- 4:50Don't Contort Your App Architecture
- 6:01Android Dev Summit
related talks
37mSingle Activity by Example
46mModern Android: How to ditch Activities and Fragments
38mMigrating to a Single-Activity Architecture in a Modular App
36mNavigation and the Single Activity: Learnings from a Skeptic
26mSingle activity navigation so simple even I can understand it
42mRoad to Single Activity
53mSimplified Single-Activity Apps Using Simple-Stack
30mFragments: What are they good for.
