android workshop (night of chances 2015)

71
Android Workshop Štefan Mitrík

Upload: stefan-mitrik

Post on 09-Aug-2015

83 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Android Workshop (Night of Chances 2015)

Android

Workshop Štefan Mitrík

Page 2: Android Workshop (Night of Chances 2015)

Why Android?

1 000 000 000 active users

+

Page 3: Android Workshop (Night of Chances 2015)
Page 4: Android Workshop (Night of Chances 2015)
Page 5: Android Workshop (Night of Chances 2015)

Workshop overview

• Basic theory

– Very short

– Quite a candy

• App description

– Simple architecture

• Coding

Page 6: Android Workshop (Night of Chances 2015)

Activity

Page 7: Android Workshop (Night of Chances 2015)

Activity

• Usually single screen

• Custom lifecycle

Page 8: Android Workshop (Night of Chances 2015)

3. onStop()

Activity 1. onCreate()

4. onDestroy()

2. onStart()

...

Page 9: Android Workshop (Night of Chances 2015)

Activity

• Screen orientation change

Page 10: Android Workshop (Night of Chances 2015)

Activity

Activity A

1

2

3

Page 11: Android Workshop (Night of Chances 2015)

Activity

Activity A

1

2

3

Page 12: Android Workshop (Night of Chances 2015)

Activity

Activity A Activity B

1

2

3

2

Page 13: Android Workshop (Night of Chances 2015)

Activity

Activity A Activity B

1

2

3

2 Intent

Page 14: Android Workshop (Night of Chances 2015)

Intent

Page 15: Android Workshop (Night of Chances 2015)

Intent

Activity A Activity B

1

2

3

2

Intent

Activity B

Item 2

Page 16: Android Workshop (Night of Chances 2015)

Intent

start external app

Page 17: Android Workshop (Night of Chances 2015)

Intent - start

external app

Activity A

1

2

3

Intent

open

website

eset.com

Page 18: Android Workshop (Night of Chances 2015)

Apps lifecycle

Page 19: Android Workshop (Night of Chances 2015)

Apps lifecycle

Page 20: Android Workshop (Night of Chances 2015)

Apps lifecycle

Page 21: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Page 22: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

onCreate()

Page 23: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Page 24: Android Workshop (Night of Chances 2015)

Memory (RAM)

onStop()

Page 25: Android Workshop (Night of Chances 2015)

Memory (RAM)

Page 26: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

onCreate()

Page 27: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Page 28: Android Workshop (Night of Chances 2015)

Memory (RAM)

onStop()

Page 29: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Page 30: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Low memory

Page 31: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Low memory onDestroy()

Page 32: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Page 33: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

onCreate()

Page 34: Android Workshop (Night of Chances 2015)

How to work in background? For example music player

Page 35: Android Workshop (Night of Chances 2015)

Service

• Long running operations

• Custom lifecycle

• No UI

Page 36: Android Workshop (Night of Chances 2015)

Activity A

Playlists

Service – Playing music

Service

Activity B

Player controls

Page 37: Android Workshop (Night of Chances 2015)

Activity A

Playlists

Service – Playing music

Service

Activity B

Player controls

Page 38: Android Workshop (Night of Chances 2015)

Activity A

Playlists

Service – Playing music

Service

Activity B

Player controls

play pause

Page 39: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Low memory

App with

service

Page 40: Android Workshop (Night of Chances 2015)

Apps lifecycle

Memory (RAM)

Low memory onDestroy()

App with

service

Page 41: Android Workshop (Night of Chances 2015)

Broadcasts

Page 42: Android Workshop (Night of Chances 2015)

Broadcasts

Page 43: Android Workshop (Night of Chances 2015)

Broadcasts

Broadcast

receivers

Page 44: Android Workshop (Night of Chances 2015)

Broadcasts

Broadcast

receivers

Incomming

message

Page 45: Android Workshop (Night of Chances 2015)

Broadcasts

Broadcast

receivers

Incomming

message

Page 46: Android Workshop (Night of Chances 2015)

• Activity – usually single screen

• Service – background, long running

• Intent – communication (inner/inter)

• Broadcast – data/events propagation

Theory summary

Page 47: Android Workshop (Night of Chances 2015)

Problem to solve

Page 48: Android Workshop (Night of Chances 2015)
Page 49: Android Workshop (Night of Chances 2015)
Page 50: Android Workshop (Night of Chances 2015)

Measure phone usage

Page 51: Android Workshop (Night of Chances 2015)

Inspiration

Page 52: Android Workshop (Night of Chances 2015)
Page 53: Android Workshop (Night of Chances 2015)
Page 54: Android Workshop (Night of Chances 2015)
Page 55: Android Workshop (Night of Chances 2015)

Display

Statistics

Page 56: Android Workshop (Night of Chances 2015)

Display

Statistics

Page 57: Android Workshop (Night of Chances 2015)

Architecture

Single Activity App

UML 5.5 notation

Page 58: Android Workshop (Night of Chances 2015)

Architecture

Single Activity App

Page 59: Android Workshop (Night of Chances 2015)

Architecture Broadcast receiver

(display on/off)

Single Activity App

Page 60: Android Workshop (Night of Chances 2015)

Architecture Broadcast receiver

(display on/off)

screen turned on

Single Activity App

Page 61: Android Workshop (Night of Chances 2015)

Architecture Broadcast receiver

(display on/off)

screen turned on

Service

Single Activity App

Page 62: Android Workshop (Night of Chances 2015)

Let’s code!

Page 63: Android Workshop (Night of Chances 2015)

Step 1

MainActivity.java

WakeUps Application

AndroidManifest.xml

• Declarations

• Permissions

• …

Page 64: Android Workshop (Night of Chances 2015)

Step 2

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

Page 65: Android Workshop (Night of Chances 2015)

Step 2

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

1 Start Service

Page 66: Android Workshop (Night of Chances 2015)

Step 2

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

1 Start Service

2

Listen to OFF

broadcasts

Page 67: Android Workshop (Night of Chances 2015)

Step 2

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

1 Start Service

2

Listen to OFF

broadcasts

3

Display “Hello Kitty” message

when screen turns on

4

Page 68: Android Workshop (Night of Chances 2015)

Step 3

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

ON/OFF 5

Pass info to

service

Page 69: Android Workshop (Night of Chances 2015)

Step 4

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

ON/OFF

6 Calculate

last wake up

duration

Persistence Helper

Page 70: Android Workshop (Night of Chances 2015)

Step 5

MainActivity

WakeUps Application

Service DisplayStatsService

ScreenBroadcastReceiver

ON/OFF

Display total

wake ups

number Persistence Helper

7

Page 71: Android Workshop (Night of Chances 2015)

Thank you!