Reputation: 67
See the below code:
if (!mBluetoothAdapter.isEnabled()) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
Why? This is actually quite common in MCU programming, but this is java application we are talking about why? Doesn't make any sense.
Upvotes: 0
Views: 38
Reputation: 140427
I agree; I can't see any reason why such kind of double checking would have any reasonable effect.
It looks like bad practice and everybody just copying it without further thinking (maybe maybe there would be some sense if the second check would go after the new Intent
line before calling startActivity ... but as above, no effects besides confusing the reader.
As this code simply runs the same check twice; without any steps in between that could have side effects on the "thing that is checked".
Upvotes: 1