[Individual presentation] android fragment

Preview:

Citation preview

Android Fragments:Modularity

is the way!

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:

gabriele.vecchia91@gmail.com

WHERE WE START1

WHERE WE START

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

◦ University Projects ◦ Various jobs ◦ Personal Interest

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.

FRAGMENTS Are what we need, but what

we don’t know to have

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.

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.

SMARTPHONE BEHAVIOUR

Place your screenshot here

ListView FrameLayout

Fragment 1 Fragment 2

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?

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.

A

Resumed

Stopped

PausedStarted

Destroyed

Create

onStart()

onCreate()

onStop()

onPause()onResume()

onStart()onResume()

onDestroy()

onResume()

ACTIVITY LYFECYCLE

F

Fragment Start

FragmentIs Running

onCreate()

onAttach()

FRAGMENT LYFECYCLE

onCreateView()

onActivityCreated()

onStart()

onResume()

Fragment End

onDestroy()

onDetach()

onDestroyView()

onStop()

onPause()

ACTIVITY vs FRAGMENT: CODE SNIPPET

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

We can normally launch the activity

DEMO XML

DEMO CODE SNIPPET

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!

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.

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:

Thanks!ANY QUESTIONS?You can find me atgabriele.vecchia91@gmail.com

Recommended