1. Trang chủ
  2. » Nghệ sĩ và thiết kế

SERVICE AND NOTIFICATION

42 8 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 42
Dung lượng 2,91 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

• This type of service, is created and started when a component such as an activity calls the startService method to start it.. • Which is a service that does not return a result to the[r]

Trang 1

SERVICE AND NOTIFICATION

LECTURER: VÕ TẤN DŨNG

SUBJECT: MOBILE DEVICE PROGRAMMING

(ANDROID)

Trang 2

APPLICATION

Trang 3

HOW TO WORK WITH THE APPLICATION OBJECT

Description:

• To store data and methods that apply to the entire application, you can extend the Application class and add instance variables and methods The Application object is created when the app starts and remains available until the app ends.

• To run code only once when the application start, you can override the onCreate method of your custom Applications class.

Trang 4

Starting point for the NewsReaderApp class

Trang 5

HOW TO REGISTER THE APPLICATION OBJECT

Trang 8

SERVICE

Trang 9

HOW TO WORK WITH SERVICES

Trang 10

UNBOUND SERVICE

Description:

• This type of service, is created and started when a component such as an activity calls the startService method to start it.

• Which is a service that does not return a result to the caller.

• The service runs until it’s stopped.

Unbound service is stopped in one of three ways:

• First, another component such as an activity can call the stopService method to stop it.

• Second, the service can call the stopSelf method to stop it itself.

• Third, Android can stop the service when the user turns off the device runs low on

memory.

Trang 11

BOUND SERVICE

Description:

• Which is a service that interact with one or more components.

• This type of service is started when a component calls the bindService method to bind to it.

• Multi components can bind to the service at the same time.

• When all of them unbind, the service is destroyed.

Trang 12

THE LIFECYCLE OF A SERVICE

Trang 13

HOW TO CREATE A SERVICE

(UNBOUND SERVICE)

Three classes are needed to implement a service: Service, Intent and IBinder

A service implements four methods that you typically need for an unbound service

onCreate method is called when the service is first created It is a good place to put code that’s only executed multiple times

onStartCommand method is executed each time a component uses the startService method to start this service This method return one of three constants:

Trang 14

THREE CONSTANTS OF THE onStartCommand()

Trang 16

HOW TO REGISTER A SERVICE

Trang 17

HOW TO START AND STOP A SERVICE

Trang 18

HOW TO STOP AND STOP A SERVICE

Trang 19

HOW TO USED THREADS WITH SERVICES

Trang 22

HOW TO TEST A SERVICE

Trang 23

HOW TO VIEW ALL SERVICES

Trang 25

NOTIFICATION

Trang 26

HOW TO WORK WITH NOTIFICATIONS

Trang 27

• Notification

• Notification area

• Notification drawer

Trang 28

PENDING INTENT

Trang 29

HOW TO CREATE AN PENDING INTENT

Trang 32

HOW TO CREATE A NOTIFICATION

Trang 34

HOW TO WORK WITH SYSTEM SERVICES

Trang 37

HOW TO CHECK IF A NETWORK CONNECTION IS AVAILABLE

Trang 40

THE NEWS READER APP

Read sample code in “Murach’s Android Programming”

(form page396 to page 405)

• Download, Upload feeds

• Display a notification whenever an updated feed is available

• Add a custom Application object to store the milliseconds for the current news feed and to start the service (to control which is the new feed and which is the old feed)

Trang 41

CLASSES OF NEWS READER APP

Trang 42

END

Ngày đăng: 16/12/2020, 13:17

TỪ KHÓA LIÊN QUAN

w