Using android.content.Context
will not work as it does not implement android.os.Parcelable
.
However, if you have a class ( MyExampleParcelable
for example) that you want to transfer to the AIDL interface (& actually implementing Parcelable
), you create a .aidl
file, MyExampleParcelable.aidl
, in which you write:
package the.package.where.the.class.is; parcelable MyExampleParcelable;
Now, if you desperately don't want to talk about processes, you have to consider local services.
Edit (a little more useful):
Is this a local service (i.e. will only be used in your own application and process)? In these cases, it is usually simply best to implement a binder and return it directly.
public class SomeService extends Service { .... .... public class SomeServiceBinder extends Binder { public SomeService getSomeService() { return SomeService.this; } } private final IBinder mBinder = new SomeServiceBinder(); @Override public IBinder onBind(Intent intent) { return mBinder; } public void printToast(Context context, String text) {
Basically, when an Activity
tied to your service, it simply translates the resulting IBinder
into SomeService.SomeServiceBinder
, calls SomeService.SomeServiceBinder#getSomeService()
- and bang , access to the executable instance of Service
+, you can call the material in your API.
Jens source share