Android Programming Tutorials

(Romina) #1
No, Really Listening To Your Friends

List<Twitter.Status> timeline=client.getFriendsTimeline();

for (Twitter.Status s : timeline) {
if (!seenStatus.contains(s.id)) {
l.callback.newFriendStatus(s.user.screenName, s.text,
s.createdAt.toString());
seenStatus.add(s.id);
}
}
}
catch (Throwable t) {
android.util.Log.e("PostMonitor",
"Exception in poll()", t);
}
}

Step #3: Manage the Service and Register the Account..................


Next, we need to take steps in Patchy to connect to the PostMonitor service


and arrange to get callbacks when new timeline entries are ready.


First, modify onCreate() in Patchy to call bindService(), which will auto-


create our PostMonitor service and give us control when it has been started


and bound:


bindService(new Intent(this, PostMonitor.class), svcConn,
BIND_AUTO_CREATE);

Specifically, it gives us control via a ServiceConnection object, which you will


need to add as a data member of Patchy:


private ServiceConnection svcConn=new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder binder) {
service=(IPostMonitor)binder;

try {
service.registerAccount(prefs.getString("user", null),
prefs.getString("password", null),
listener);
}
catch (Throwable t) {
Log.e("Patchy", "Exception in call to registerAccount()", t);
goBlooey(t);
}
}

186
Free download pdf