Android Programming Tutorials

(Romina) #1
Your Friends Seem Remote

At this point, the Patchy project should compile cleanly. It will not run,


though, without the corresponding service.


Step #6: Implement the Service Side................................................


Finally, we need to make similar sorts of changes on the PostMonitor service.


First, modify TMonitor/AndroidManifest.xml to add an (so


Patchy can reference it from another process and package) and add the


INTERNET permission that JTwitter will need:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="apt.tutorial.three"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="@string/app_name">
<service android:name=".PostMonitor">
<intent-filter>
<action android:name="apt.tutorial.IPostMonitor" />
</intent-filter>
</service>
</application>
</manifest>

Next, change our binder object from being an instance of LocalBinder to


being an instance of an IPostMonitor.Stub anonymous inner class instance


as follows:


private final IPostMonitor.Stub binder=new IPostMonitor.Stub() {
public void registerAccount(String user, String password,
IPostListener callback) {
Account l=new Account(user, password, callback);

poll(l);
accounts.put(callback, l);
}

public void removeAccount(IPostListener callback) {
accounts.remove(callback);
}
};

208
Free download pdf