Yes, ServiceConnection is the callback, and it won't happen until you return
to your message loop (which will be after returning from onResume()).

2009/9/28 bear tung <beart...@gmail.com>

> Thanks.
> I want to know when the the service connection is connected. It seems like
> won't connected before the ui show up.
>
> The thing i what to do is show the UI based on the servie's some function's
> return value. There is something like callback function when the connection
> done?
>
>
> On Tue, Sep 29, 2009 at 12:14 AM, Marco Nelissen <marc...@android.com>wrote:
>
>>
>> You need to wait until you actually receive the service connection
>> callback before you do anything with the service. You can't simply
>> assume that the callback has already happened when you reach your
>> onStart.
>>
>>
>> On Mon, Sep 28, 2009 at 7:36 AM, bear tung <beart...@gmail.com> wrote:
>> > 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
>> >
>> > >
>> >
>>
>>
>>
>
>
> --
> 董利明(Bear)
> 软件工程师  Software Engineer
> Douban Inc.
> office: +86 8479 9008
> Mobile: 1358 1725 230
> No.14 Jiuxianqiao Road, Area 51 A1-1-2106, Beijing 100016 , China
> 北京市酒仙桥路14号51楼A1区1门2016,100016
>
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
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