Android Programming Tutorials

(Romina) #1

TUTORIAL 17


Listening To Your Friends


In this tutorial, we will start watching our friends' timelines, polling them


for updates in a background thread managed by a service.


Step-By-Step Instructions.........................................................................


First, you need to have completed the previous tutorial. If you are


beginning the tutorials here, or if you wish to not use your existing work,


you can download a ZIP file with all of the tutorial results, and you can copy


the 16-JAR edition of Patchy to use as a starting point.


Step #1: Create a Service Stub............................................................


Since we are creating a service to monitor information related to our


account, let us create a service named PostMonitor (so named because


identi.ca supports the original Twitter API). Create a file named


Patchy/src/apt/tutorial/two/PostMonitor.java with the following content:


package apt.tutorial.two;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class PostMonitor extends Service {
@Override
public void onCreate() {
super.onCreate();

177
Free download pdf