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

2 Running jobs in the background
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
IntentService class public class RSSPullService extends IntentService { @Override protected void onHandleIntent(Intent workIntent) { // Gets data from the incoming Intent String dataString = workIntent.getDataString(); ... // Do work here, based on the contents of dataString }

4 Running jobs in the background
Manifest entry <service android:name=".RSSPullService" android:exported="false"/>

5 Sending a work request As with most operations, this begins with creating an intent object Intent = new Intent(getActivity(), RSSPullService.class); intent.setData(Uri.parse(dataUrl)); Then you call getActivity().startService(intent)

6 Sending results Results must be sent to a broadcast service
But there is a LocalBroadcastManager that can be used to limit recipients to your own application.

7 Receiving Results Your app must define a broadcast receiver
And register with the LocalBroadcastManager For receiving local messages only You can apply an IntentFilter to restrict the type of broadcast messages that you will actually receive.

8 Response to Broadcast The tutorials emphasize that you should not start an activity in response to a broadcast event However, you can send a Notification to the user.

9 Networked Communication
Network Service Discovery Advertise your app's service Find services on your network

10 Network Service Discovery
Registering your service NsdServiceInfo class Info.setService("Name"); Info.setServiceType("_http._tcp."); Info.setPort(<port number>);

11 P2P Over Wifi The router is optional Longer range than bluetooth

12 Network Connections <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

13 Threading for a responsive app
Network activities should not be performed on the main activity thread. Unpredictable delays AsyncTask doInBackgroundMethod OnPostExectute Can make UI changes!


Download ppt "Reactive Android Development"

Similar presentations


Ads by Google