My activity bind a service.  I want to call the service's function in
actitity's onStart/onCreate function, but it doesn't work.
The service started suncess but the connection is null.

When I just call the service's function in other function (onClick for
example),  it works well.

thanks for help.

here is my code:

public class AidlTest extends Activity
{
    private static final String TAG = "AidlTest";
    IAidlService mService;

    private OnClickListener mCorkyListener = new OnClickListener() {
        public void onClick(View v) {
            test();
        }
    };

    private ServiceConnection mConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName className,  IBinder
service) {
            mService = IAidlService.Stub.asInterface(service);
        }
        public void onServiceDisconnected(ComponentName className) {

            mService = null;
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        TextView v = new TextView(this);
        setContentView(v);
        v.setOnClickListener(mCorkyListener);
        Log.v(TAG, IAidlService.class.getName().toString());
        Intent intent = new Intent(IAidlService.class.getName());
        bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    public void onStart(){
        super.onStart();
        Log.d(TAG, "onStart");
        test();
        }
    }

    public void test(){
        if (mService == null){
            Log.d(TAG, "mService is NULL");
        }
        try {
            mService.test();
        }catch (RemoteException e){
            Log.d(TAG, e.toString());
        }
    }
}



Bear

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to