Android Programming Tutorials

(Romina) #1
Listening To Your Friends

private void poll() {
Twitter client=new Twitter(); // need credentials!
List<Twitter.Status> timeline=client.getFriendsTimeline();

for (Twitter.Status s : timeline) {
if (!seenStatus.contains(s.id)) {
// found a new one!
seenStatus.add(s.id);
}
}
}

Of course, eventually, we will need to alert Patchy to the new statuses, but


we can leave that for the next tutorial.


Step #5: Set up the Public API............................................................


Finally, we need to begin the process of adding a public API that the Patchy


activity will be able to access.


First, we should define a Java interface that will represent our public API.


Create a src/apt/tutorial/IPostMonitor.java file with the following content:


package apt.tutorial;

public interface IPostMonitor {
}

Then, we need to create a "binder" that implements this API. The binder


will be supplied to Patchy when it binds to the PostMonitor service. So, add


the following inner class to PostMonitor:


public class LocalBinder extends Binder implements IPostMonitor {
void registerAccount(String user, String password) {
}
}

Next, create an instance of our LocalBinder as part of initializing our


PostMonitor instance:


private final Binder binder=new LocalBinder();

181
Free download pdf