Binding to a service is asynchronous. You should maybe disable the
button that binds and unbinds until you are sure that you are
actually, respectively, bound and unbound.

You do that by keeping track of when the ServiceConnection object's
onServiceConnected() and onServiceDisconnected() functions are called.
Before that, you are not really connected, or disconnected, you are
just in the process of being connected or disconnected.


On Jul 30, 6:22 am, Mogimo <mogimo...@gmail.com> wrote:
> Hello,
>
> I made a code for my understanding of Android Service class.
> It has just a single Activity and Service in apk. Service is the same
> as the sample code of API reference as 
> below;http://developer.android.com/intl/ja/reference/android/app/Service.ht...
>
> A client side is an Activity based on the above sample, and just added
> the following code;
>         public void onCreate(Bundle savedInstanceState) {
>                 super.onCreate(savedInstanceState);
>                 setContentView(R.layout.local_service_tset);
>
>                 CheckBox checkBox = (CheckBox) findViewById(R.id.checkbox);
>                 checkBox.setOnClickListener(new View.OnClickListener() {
>                         @Override
>                         public void onClick(View v) {
>                                 CheckBox cb = (CheckBox) v;
>                                 if (cb.isChecked()) {
>                                         doBindService();
>                                 } else {
>                                         doUnbindService();
>                                 }
>                         }
>                 });
>         }
> My sample application has a check box which starts(binds)/unbind to
> the local service on a single process. The local service instance is
> created by every bind request (and destroyed by every unbind).
>
> If I press the button repeatedly, then LocalService$LocalBinder is
> leaked!!
> The problem is not resolved even If I set an obtained binder to null
> (like below).
>                                 } else {
>                                         doUnbindService();
> +                                       mBoundService = null;
>                                 }
>
> Please help! How to resolve this problem?

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