Whoops, yeah that is a bug. Thanks for finding it. I'll fix it in the next update.
On Thu, Mar 10, 2011 at 1:55 AM, Pete Doyle <petedo...@gmail.com> wrote: > Ran into this issue tonight on my Droid (2.2). I think there's an issue in > FragmentActivity.startActivityFromFragment(...). > > YMMV, but this seems to fix it for me: > > https://github.com/petedoyle/android-support-v4-googlemaps/commit/06307de35a9de0a89ff52bb42a358ba6740e542c > > Basically there are two issues: > 1) "(fragment.mIndex+1)<<16" should be in parentheses since + has > precedence over << in Java > 2) requestCode*0xffff should be requestCode&0xffff. (I think the goal is > to strip all but the first 16 bits of the request code). > > To understand the fix, assume you have a fragment index of 0 and a > requestCode of 1. > > With the current code: > (fragment.mIndex+1)<<16 + (requestCode*0xffff) > = (0+1)<<16 + (1*0xFFFF) > = (1)<< (16 + 0xFFFF) // since + has precedence over << > = 1<<65551 > = 32768 // according to my debugger > = 1000 0000 0000 0000 // fragment index is lost, request code changes from > 1 to 32768 > > With this change: > ((fragment.mIndex+1)<<16) + (requestCode&0xffff) > = ((0+1)<<16) + (1&0xFFFF) > = (1<<16) + 1 > = 65536 + 1 > = 65537 > = 1 0000 0000 0000 0001 > > Thanks, > Pete > > On Wed, Mar 9, 2011 at 9:20 AM, Dianne Hackborn <hack...@android.com>wrote: > >> Does the API demo for this work wherever you are running it? I have >> tested it on 3.0, 2.3, and 1.6, and it works in those places, not would I >> expect it to have any trouble elsewhere. (How this works is very simple, >> it just masks out the top X bits of the request code to determine which >> fragment to deliver the result to.) >> >> Also of course if you are overriding FragmentActivity.onActivityResult(), >> you *do* need to be sure to call the inherited version. The behavior here >> is slightly different than the HC implementation; the activity method will >> always be called first. >> >> >> On Wed, Mar 9, 2011 at 8:14 AM, drasticp <drast...@gmail.com> wrote: >> >>> I have an application that targets 2.1. I'm using the Android >>> Compatibility Package to migrate the code in my Activities to >>> Fragments. I had an Activity which was launching a contact picker as >>> follows: >>> >>> Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, >>> Contacts.CONTENT_URI); >>> startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT); >>> >>> The result was appropriately handled in the onActivityResult for the >>> Activity: >>> >>> @Override >>> public void onActivityResult(int requestCode, int resultCode, Intent >>> data) { >>> if (resultCode != Activity.RESULT_OK) return; >>> switch (requestCode) { >>> case CONTACT_PICKER_RESULT: >>> handleResult(data); >>> break; >>> } >>> } >>> >>> Now, I've migrated both the startActivityForResult call and the >>> onActivityResult into a Fragment. I have also extended >>> FragmentActivity in the hosting Activity. >>> >>> The contact picker still launches correctly, but onActivityResult in >>> the fragment is never called. If I override onActivityResult in the >>> FragmentActivity, it *IS* called. However, I don't want to handle the >>> result there because it breaks the encapsulation philosophy of the new >>> fragments. >>> >>> Shouldn't onActivityResult in the fragment be called? Am I missing >>> something? Thanks for your assistance! >>> >>> -- >>> 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+unsubscr...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/android-developers?hl=en >>> >> >> >> >> -- >> Dianne Hackborn >> Android framework engineer >> hack...@android.com >> >> Note: please don't send private questions to me, as I don't have time to >> provide private support, and so won't reply to such e-mails. All such >> questions should be posted on public forums, where I and others can see and >> answer them. >> >> -- >> 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+unsubscr...@googlegroups.com >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en >> > > -- > 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+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en