21
What Androids are Made of

What Androids Are Made Of

Embed Size (px)

Citation preview

Page 1: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 1/21

Page 2: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 2/21

Main Building Blocks

• Android building blocks make it easy to breakdown an application into conceptual units,work on them independently and easily put

them together into a complete package – Activities

 – Services

 – Intents

 – Broadcast receivers

 – Content providers

Page 3: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 3/21

Activities

• A single screen that a user can see

• An application typically has multiple activities

Concept of activities can be easily understandby comparing an Android application with a

“website”  

Page 4: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 4/21

Activity Life Cycle

• Activity life cycle is managed by Activity

Manager

Page 5: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 5/21

Activity Life Cycle

• Starting State

 – When an activity doesn’t exist in memory 

 – After starting state, an activity enters the running

state

 – Transition from starting state to running state is

one of the most expensive operations in terms of

computing time and battery life

Page 6: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 6/21

Page 7: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 7/21

Activity Life Cycle

• Paused State

 – When an activity is not in focus

 – But it is still visible

 – For example, a dialog box coming in front of an

activity can cause the activity to pause

 – Paused activities still have high priorities in terms

of getting memory and other resources

Page 8: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 8/21

Activity Life Cycle

• Stopped State

 – When an activity is not visible, but still in memory

 – A stopped activity can be moved back to either

the running state or it could be destroyed

 – Why do you think the system keeps activities in

stopped state?

Page 9: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 9/21

Activity Life Cycle

• Destroyed State

 – When an activity is no longer in the memory

 – Before an activity gets destroyed, it can perform

certain actions, such as saving unsaved data.

 – Remember, there is no guarantee that an activity

will be stopped before being destroyed

 – Therefore, it is important to do important stuff,such as saving data, en route to a paused state.

Page 10: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 10/21

Intents

• Messages that are sent among the major

building blocks (for example, to start or stop

an activity or service)

• Intents are asynchronous

• Could be explicit (the sender clearly mentions

a specific receiver) or implicit (the sender

mentions the type of receiver)

Page 11: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 11/21

Intents Example

Page 12: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 12/21

Services

• Run in the background and don’t have any

user interface components

• Useful for actions that we want to perform for

a while, regardless of what is on the screen

• For example, listening music while flipping

between applications

Page 13: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 13/21

Service Life Cycle

• Services have a much simpler life cycle than

activities

Page 14: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 14/21

Content Providers

• Interfaces for sharing data between

applications

• Data that belongs to an application is usually

isolated

• Although we also use intents for sharing

information, content provider are suited for

large datasets

Page 15: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 15/21

Content Providers

Page 16: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 16/21

Content Provider Example

Page 17: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 17/21

Broadcast Receivers

• Android’s implementation of a system-wide

publish/subscribe mechanism.

• They are also called observer patterns

• The receiver is a piece of code that gets

activated once an event to which it has

subscribed occurs

Page 18: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 18/21

Application Context

• Android major building blocks together make up anapplication

• They live inside the same application context

• Application context refers to the application

environment• It gets created whenever first component of an

application starts (that component can be any buildingblock)

Reference to context can be obtained – Context.getApplicationContext()

 – Activiy.getApplication()

Page 19: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 19/21

Page 20: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 20/21

• Step # 1: Java

 – When you write Android applications, you

typically write them in Java source code.

 – That Java source code is then turned into the stuff

that Android actually runs (Dalvik bytecode in an

APK file). – Hence, the first thing you need to do is get set up

with a Java development environment and be

ready to start writing Java classes.

Page 21: What Androids Are Made Of

8/13/2019 What Androids Are Made Of

http://slidepdf.com/reader/full/what-androids-are-made-of 21/21

• Step # 1: Java

• This is what we did in the last week

• Step # 2: Install the Android SDK