// myService.java
package com.google.android.ZigbeeApp;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.Parcel;
import android.util.Log;
import android.widget.Toast;
public class myService extends Service{
private IBinder myBinder = null ;
@Override public void onCreate() {
myBinder = new myBinder(this.getApplicationContext());
}
@Override public IBinder onBind(Intent intent){
return myBinder ;
}
// myBinder.java
class myBinder extends Binder {
private Context context ;
private myService srv ;
public myBinder(Context ctx, myService service){
context = ctx ;
srv = service;
}
@Override public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
throws android.os.RemoteException
{
if (code == 0) {
Intent intent = new Intent("android.intent.action.MY_BROADCAST");
intent.putExtra("inta", 101) ;
sendBroadcast(intent); // 传送给Activity
}
return true;
}
}