16
Android – Message Yong Heui Cho @ Mokwon University Some of slides are referred to: [1] Nitin Ramchandani, Android OS, slideshare.

Android - Message

Embed Size (px)

Citation preview

Page 1: Android - Message

Android –Message

Yong Heui Cho @ Mokwon University

Some of slides are referred to:[1] Nitin Ramchandani, Android OS, slideshare.

Page 2: Android - Message

2

Smart Device Structure

3. Basic Android OS

4. Android – Application Framework5. Android – Message

6. Android – BroadcastRe-ceiver

Page 3: Android - Message

3

Application

Application Structure

Activity

Context

OS

Resources

Service

lifecycle

Page 4: Android - Message

4

Application Lifecycle

I. In Android, every application runs in their own process.

II. Processes are started or stopped as needed to run application components.

III. A process may be killed to reclaim resources.

□ Courtesy to Nitin Ramchandani, Android OS, slideshare.

Page 5: Android - Message

5

Activity Lifecycle (I)

Page 6: Android - Message

6

• onCreate(Bundle): This is called when the activity first starts up.

• onStart( ): This indicates the activity is about to be displayed to the user.

• onResume( ): This is called when your activity can start interacting with the user. This is a good place to start animations and music.

• onPause( ): This runs when the activity is about to go into the background, usually because another activity has been launched in front of it. This is where you should save your program’s persistent state, such as a database record being edited.

Activity Lifecycle (II)

□ Courtesy to Nitin Ramchandani, Android OS, slideshare.

Page 7: Android - Message

7

• onStop( ): This is called when your activity is no longer visible to the user and it won’t be needed for a while. If memory is tight, onStop( ) may never be called (the system may simply terminate your process).

• onRestart( ): If this method is called, it indicates your activity is being redisplayed to the user from a stopped state.

• onDestroy( ): This is called right before your activity is destroyed. If memory is tight, onDestroy( ) may never be called (the system may simply terminate your process).

Activity Lifecycle (III)

□ Courtesy to Nitin Ramchandani, Android OS, slideshare.

Page 8: Android - Message

8

• onSaveInstanceState(Bundle): Android will call this method to allow the activity to save per-instance state, such as a cursor position within a text field. Usually you won’t need to override it because the default implementation saves the state for all your user interface

controls automatically.

• onRestoreInstanceState(Bundle): This is called when the activity is being reinitialized from a state previously saved by the onSaveInstanceState( ) method. The default implementation restores the state of your user interface.

Save & Restore

□ Courtesy to Nitin Ramchandani, Android OS, slideshare.

Page 9: Android - Message

9

Lifecycle Comparison

Run Terminate

onCreate() onDestroy()

onStart() onStop()

onResume() onPause()

onRestart() -

onRestoreInstanceState() onSaveInstanceState()

Page 10: Android - Message

10

Summary of Lifecycle

Page 11: Android - Message

11

Android vs. Windowstype Android Windows

CPU optimal fast

battery small power supply

memory mobile DRAMsmall

DRAMlarge

message handler message (Message) or action (String) message (int)

termination app lifecycle permanent

function call call & proceed call & wait or call & proceed

Page 12: Android - Message

12

MVC Components

Page 13: Android - Message

13

Android Msg Handler

• Message: containing a description and arbitrary data object

• Runnable: a command that can be executed• Handler: allows you to send and process

Message and Runnable • Looper: used to run a message loop for a thread

Page 14: Android - Message

14

Concept of Multithread

Page 15: Android - Message

15

Android Rules• Do not block the UI thread (or

main thread).• Do not access the Android UI

toolkit from outside the UI thread.

Page 16: Android - Message

16

Event Listener• Interface to process specific

events