14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11: Advanced Android <strong>Development</strong><br />

358<br />

}<br />

}<br />

out.writeDouble(location.getLatitude());<br />

out.writeDouble(location.getLongitude());<br />

out.writeString(link);<br />

public static final Parcelable.Creator CREATOR =<br />

new Parcelable.Creator() {<br />

public Quake createFromParcel(Parcel in) {<br />

return new Quake(in);<br />

}<br />

public Quake[] newArray(int size) {<br />

return new Quake[size];<br />

}<br />

};<br />

public int describeContents() {<br />

return 0;<br />

}<br />

Now that you’ve got a Parcelable class, you need to create an AIDL defi nition to make it available when<br />

defi ning your Service’s AIDL interface.<br />

The following code snippet shows the contents of the Quake.aidl fi le you need to create for the Quake<br />

class defi ned above:<br />

package com.paad.earthquake;<br />

parcelable Quake;<br />

Remember that when you’re passing class objects between processes, the client process must understand<br />

the defi nition of the object being passed.<br />

Creating the AIDL Defi nition<br />

In this section, you will be defi ning a new AIDL interface defi nition for a Service you’d like to use<br />

across processes.<br />

Start by creating a new .aidl fi le within your project. This will defi ne the methods and fi elds to include<br />

in an Interface that your Service will implement.<br />

The syntax for creating AIDL defi nitions is similar to that used for standard Java interface defi nitions.<br />

Start by specifying a fully qualifi ed package name, then import all the packages required. Unlike<br />

normal Java interfaces, AIDL defi nitions need to import packages for any class or interface that isn’t a<br />

native Java type even if it’s defi ned in the same project.<br />

Defi ne a new interface, adding the properties and methods you want to make available.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!