-1

I have a code snippet as follows:

switch (status.getStatusCode()) {
     case LocationSettingsStatusCodes.SUCCESS:
          Log.d("Location", "onResult: success");
     case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
          Log.d(TAG, "onResult: resolution needed");

 }

status.getStatusCode() return an int and all constants are int s as well.
Before switch block I log 3 values status.getStatusCode() is 0, LocationSettingsStatusCodes.SUCCESS is 0 and LocationSettingsStatusCodes.RESOLUTION_REQUIRED is 6.
But both Log.d statements are executed. I don't think the problem is related to my code because I executed the same logic with if-else.
What can be the problem?

Lucky
  • 16,787
  • 19
  • 117
  • 151
Mehrdad Shokri
  • 1,974
  • 2
  • 29
  • 45

1 Answers1

0

You need a break statement.

Without that the case will fall though into the next case....

switch (status.getStatusCode()) {
     case LocationSettingsStatusCodes.SUCCESS:
          Log.d("Location", "onResult: success");
          break;
     case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
          Log.d(TAG, "onResult: resolution needed");
          break;
 }
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97