[android-developers] Re: Binder is leaked by binding to a service
Thank you for your kind reply! On 8月2日, 午後9:12, brucko wrote: > Sorry for slow reply - been away. > > > By the way, if I changed LocalBinder to a static inner class, does it > > make sense ? > > I have made a separate generic class that usually use for all my > services ie one that I import in - just a bit of cut and paste. That > way I can reuse the code for all my Services. > > > That means to return back the same binder for all connections? > > A Java expert may correct me here - but I think you will find that > "static" is one of those words in Java that has different meanings > depending on where it is used. I believe in the case of inner classes > "static"does not mean that the inner class is the same object for all > instances of the outer class. Rather it is an object that no longer > has a reference to the outer class - and that you will need to pass a > reference in when you instantiate the inner class and get the inner > class to null out that reference when no longer required. ( if you > want to use the outer classes methods and non private fields) -- 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
[android-developers] Re: Binder is leaked by binding to a service
Sorry for slow reply - been away. > By the way, if I changed LocalBinder to a static inner class, does it > make sense ? I have made a separate generic class that usually use for all my services ie one that I import in - just a bit of cut and paste. That way I can reuse the code for all my Services. > That means to return back the same binder for all connections? A Java expert may correct me here - but I think you will find that "static" is one of those words in Java that has different meanings depending on where it is used. I believe in the case of inner classes "static"does not mean that the inner class is the same object for all instances of the outer class. Rather it is an object that no longer has a reference to the outer class - and that you will need to pass a reference in when you instantiate the inner class and get the inner class to null out that reference when no longer required. ( if you want to use the outer classes methods and non private fields) -- 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
[android-developers] Re: Binder is leaked by binding to a service
Thank you for your information!! I will keep watching it out. By the way, if I changed LocalBinder to a static inner class, does it make sense ? That means to return back the same binder for all connections? On 7月31日, 午前5:24, brucko wrote: > This appears to be a bug > > http://code.google.com/p/android/issues/detail?id=6426 > > watch out. If your LocalBinder is a non-static inner class, then you > will leak your Service as well as non-static inner classes have a > reference to the outer class. -- 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
[android-developers] Re: Binder is leaked by binding to a service
This appears to be a bug http://code.google.com/p/android/issues/detail?id=6426 watch out. If your LocalBinder is a non-static inner class, then you will leak your Service as well as non-static inner classes have a reference to the outer class. -- 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
[android-developers] Re: Binder is leaked by binding to a service
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 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