ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Activities vs Fragments
By: Abdel Rahman Shaltoot
? A look at how we (used to) do things
? Comparison between coding styles
? Building for modularity and testability
? Pros and cons with an all Activity build
? Pros and cons with an all Fragment build
? Proposing a yet-to-be-tested-enough solution
Overview
Simple Weather App
Simple Weather App
Simple Weather App
Simple Weather App
Activities vs fragment
Simple Weather App
Simple Weather App++
Simple Weather App++
Simple Weather App++
Activities vs fragment
So let¡¯s change that
Define and Separate Your
Concerns
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Simple Weather App (Cool
Edition)
Umm¡­ How is related to
Activities vs Fragments again?
Build for Modularity and Testability
Pros of an all Activity build
? Activities mainly act as view controllers, which allows
them to hold their own state (Context).
? Testing Activities is much easier than Fragments
? Back-stack handling is done by the framework in the
background
Cons of an all Activity build
? Activities mainly act as view controllers, which allows
them to hold their own state (Context)
? Testing Activities is much easier than Fragments
? The views created in Activities may not always be the
best suited views for different sizes of screens
? Activities can¡¯t be reused as a whole
Pros of an all Fragment build
? Fragments, by design, are made to be reusable
components
? They are the ¡°only¡± way to optimize our apps¡¯ UI to fit
bigger screens
Cons of an all Fragment build
? Complicated life-cycle events that are already nested
inside the Activity¡¯s life-cycle events
? Fragments can¡¯t communicate amongst each other
unless it is through an Activity
? Testing Fragments requires the presence of the
Activity¡¯s Context.
? Handling the changes in the back-stack must be done
manually
Custom Views to the Rescue

More Related Content

Activities vs fragment