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

SERVICE AND NOTIFICATION

42 6 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

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]

(1)

SERVICE AND NOTIFICATION

LECTURER: VÕ TẤN DŨNG

(2)(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.

(4)(5)(6)(7)(8)(9)(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.

(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.

(12)(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:

• 1) START_STICKY

• 2) START_NOT_STICKY

• 3) START_REDELIVER_INTENT

onBind method is executed when another component attempts to bind to the service This method returns an Ibinder object that the component can use to interact with the service

(14)(15)(16)(17)(18)(19)(20)(21)(22)(23)(24)(25)(26)(27)

NOTIFICATION

• Notification

(28)(29)(30)(31)(32)(33)(34)(35)(36)(37)(38)(39)(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

(41)(42)

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

TỪ KHÓA LIÊN QUAN