[Individual presentation] android fragment

20
Android Fragments: Modularity is the way!

Transcript of [Individual presentation] android fragment

Page 1: [Individual presentation] android fragment

Android Fragments:Modularity

is the way!

Page 2: [Individual presentation] android fragment

Hello!

I Am Gabriele VecchiaI am here because I love to give presentations! No, really, I hope to give you some useful tips to introduce you to Android development. You can find me at:

[email protected]

Page 3: [Individual presentation] android fragment

WHERE WE START1

Page 4: [Individual presentation] android fragment

WHERE WE START

We want to start the development of an Android application for ◦ Our Startup

◦ University Projects ◦ Various jobs ◦ Personal Interest

Page 5: [Individual presentation] android fragment

WHAT WE WANT

SimplicityWe would have the tools to start to realize what we have in mind, but with the lowest effort.

Adaptability«“More” is best»! More are the device classes that we support, more user will can use the application. Interfaces are important for the usability...

ModularityNot only in the “Code side” but also in the User Interface. We can modularize the activity in a portion of UI.Multiple “activities” in the same page.

Page 6: [Individual presentation] android fragment

FRAGMENTS Are what we need, but what

we don’t know to have

Page 7: [Individual presentation] android fragment

KEY ASPECTS OF FRAGMENTS

If, on one side, we have that the Activity are navigation controllers on the other side the Fragments are content controllers.

In “fragment-based” architecture, the activities are for navigation and the fragments are for views and logic.

Page 8: [Individual presentation] android fragment

ProFragments are standalone components that can contain views, events and logic.Extends Activities so they have all them methods, but we can execute a fragment in a portion of UI !

“BE OR NOT TO BE”

ConsAs a “Side-effect”, they need a little more attention when implemented. A specially attention goes in their life-cycles. They are not well suited if we need to communicate between them.

Page 9: [Individual presentation] android fragment

SMARTPHONE BEHAVIOUR

Place your screenshot here

ListView FrameLayout

Fragment 1 Fragment 2

Page 10: [Individual presentation] android fragment

Fragments helps a lot with optimizing for various screens, they are easily managed by their parent activity, can be reused, combined and positioned at will.

WHY FRAGMENTS HERE?

Page 11: [Individual presentation] android fragment

Pla

ce y

ou

r sc

ree

nsh

ot

he

re

LANDSCAPE BEHAVIOUR

On landscape orientation the fragments can be instantiated in the same activity, like a puzzle.

Page 12: [Individual presentation] android fragment

A

Resumed

Stopped

PausedStarted

Destroyed

Create

onStart()

onCreate()

onStop()

onPause()onResume()

onStart()onResume()

onDestroy()

onResume()

ACTIVITY LYFECYCLE

Page 13: [Individual presentation] android fragment

F

Fragment Start

FragmentIs Running

onCreate()

onAttach()

FRAGMENT LYFECYCLE

onCreateView()

onActivityCreated()

onStart()

onResume()

Fragment End

onDestroy()

onDetach()

onDestroyView()

onStop()

onPause()

Page 14: [Individual presentation] android fragment

ACTIVITY vs FRAGMENT: CODE SNIPPET

With fragment we can call a specific instance to execute on start

We can normally launch the activity

Page 15: [Individual presentation] android fragment

DEMO XML

Page 16: [Individual presentation] android fragment

DEMO CODE SNIPPET

Page 17: [Individual presentation] android fragment

ALTERNATIVE TO...?

No exist real alternative to Fragments.

Its possible to emulate, more or less, them views and events behavior with:

● Create ad-hoc Activities

● WebApp loaded in the Application

● Unity3D

But are really inefficient options!

Page 18: [Individual presentation] android fragment

FINAL CONSIDERATIONS

Launching a separate activity for each app screen is terribly inefficient, since the system will try to keep them in memory as long as it can.

Use Fragments wherever is possible!Fragments can be added to Activities a runtime.More study is needed when the developing starts, but knowing how to use them give many advantages.

Page 19: [Individual presentation] android fragment

SOME USEFUL LINKS

For the template that I used visit:

https://developer.android.com/guide/components/fragments

SlideCarnival

For more details about Fragments visit the link for the documentation:

Page 20: [Individual presentation] android fragment

Thanks!ANY QUESTIONS?You can find me [email protected]