[android-developers] Mysterious behavior of switch statement inside onActivityResult
Hello,
I have the following code in class MyActivity:
public static final int REQ_CODE = 0x7fffffff;
...
startActivityForResult(intent, REQ_CODE);
...
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "#### onActivityResult: " +
Integer.toHexString(requestCode));
switch (requestCode) {
case 0:
case REQ_CODE:
Log.d(TAG, "#### REQ_CODE ####");
break;
default:
Log.d(TAG, "#### Equals: " + (requestCode == REQ_CODE));
}
}
When I run it I get the following log messages:
D/MyActivity(11505): #### onActivityResult: 7fffffff
D/MyActivity(11505): #### REQ_CODE ####
Now for the mystery. If I comment-out the "case 0" clause I get these
log messages:
D/MyActivity(11471): #### onActivityResult: 7fffffff
D/MyActivity(11471): #### Equals: true
If I comment-out the "case 0" clause and change the value of REQ_CODE
to 0x7ffffffe I get a correct result again. To make the case even more
mysterious, a similar code works perfectly well in another class,
inside a method overriding Handler.handleMessage(Message msg).
My environment:
- Ubuntu 11.10 x86 (32bit).
- Android SDK Tools r15
- ADT Version: 15.0.1.v201111031820-219398
- javac 1.6.0_26
- Project target API: 7 (Android 2.1)
Additional information:
- Building with ant does not make any difference.
- Changing Java compliance to 1.5 does not make any difference.
- The problem can reproduced 100% of the times, both on Nexus S with
Android 2.6.3 and on emulator running Android 2.1.
- No, I'm not drunk!
--
"The flames are all long gone, but the pain lingers on"
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home