Whats the correct way of calling super.onStop(), i.e, when unregistering a listener?
I have seen:
protected void onStop() {
sensorManager.unregisterListener(this);
super.onStop();
}
OR
protected void onStop() {
super.onStop();
sensorManager.unregisterListener(this);
}
You should always call it first, mostly as a protection mechanism: if there is an exception then the superclass instance method will already have been called.
It doesn't matter. Unless you are dependent on some state continuing to be initialized (and as far as any framework classes are concerned I can guarantee you aren't) you can freely call it after the superclass. If the superclass throws an exception your whole app is going to crash, so there is no reason to order one way or the other due to that.
That said, just for consistency putting these calls on the first line is nice because that is where people expect to see them and it will help avoid you making mistakes in the future such as deleting code in the method and accidentally deleting the call to the super class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With