As explained in the documentation regarding bound services, a mBound
boolean is used to know whether a service was bound in an activity. Here is an excerpt of the code example given in the documentation:
public class BindingActivity extends Activity {
LocalService mService;
boolean mBound = false;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
LocalBinder binder = (LocalBinder) service;
mService = binder.getService();
mBound = true;
}
}
Why use an additional member rather than setting mService
to null
if it is not bound? It seems redundant to me, and potentially error-prone.