Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reactive Android Development

Similar presentations


Presentation on theme: "Reactive Android Development"— Presentation transcript:

1 Reactive Android Development
CS T & CS T Summer 2016 Services, Threads, and "Push (Pull)"

2 Running jobs in the background
Last time, we talked about the Intent Service Can not interact directly with the UI Results must be sent to the activity for it to handle Work requests run sequentially If one request blocks, all others must wait until it is finished An operation running on an intent service can not be interrupted If the result is no longer desired, it must be ignored after it arrives.

3 Running jobs in the background
But earlier, we talked about Services Just a component without a UI and that can be running in the background IntentService is a subclass Regular Services run in the main thread of the application If performing an intensive or blocking task, it should launch a thread

4 Service Lifecycle

5 AsyncTask Very simple way to do work in the background
doInBackground Code that will execute in the background onPostExecute Code that will execute in the main thread Good for GUI updates. Can be cancelled! Tasks are Queued Since HONEYCOMB, AsyncTasks execute sequentially to reduce bugs caused by parallel execution.

6 Threads Regular Java Threads Lifecycle is not managed by Android
Java no longer provides mechanisms for killing threads directly My approach: Ensure that the main loop can't block indefinitely Check a 'should continue' member variable at each loop iteration Basically the same as the isCancelled method for AsyncTask

7 "Push" Notifications Most WiFi IP addresses are not routable
This isn't true on campus, but is likely to be true at a coffee shop How can a central server contact devices?

8 "Push" Notifications How can a central server contact devices?

9 "Push" Notifications How can a central server contact devices?
Let's assume that it can't!

10 "Push" Notifications How can a central server contact devices?
Let's assume that it can't! What if the device contacted the server and waited for a response?

11 "Push" Notifications Basically, I'm implementing push notifications as a sort of slow HTTP server. The client connects and tries to read the server with a long timeout. The server only replies when it has something to send.

12 The Layout

13

14

15


Download ppt "Reactive Android Development"

Similar presentations


Ads by Google