question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

using initiateScan() in android.support.v4.app.Fragment is not invoking onActivityResult()

See original GitHub issue

I tried the following inside the android.support.v4.app.Fragment:

 IntentIntegrator integrator = new IntentIntegrator(getActivity());

The constructor for the Fragment is only available for the native Fragment provided by the SDK in the device not the support-v4 or package. After deeper investigation i find out that the REQUEST_CODE: https://github.com/zxing/zxing/blob/6c522f127a0ac40b2e14518528c9547018e044b2/android-integration/src/main/java/com/google/zxing/integration/android/IntentIntegrator.java#L112

value seems the issue. It prevents later in the FragmentActivity here: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.0_r1/android/support/v4/app/FragmentActivity.java/#150 that the index is not 0. Then it traverses through all fragments and invokes onActivityResult() properly. I set a breakpoint with the debugger and modified the REQUEST_CODE and it works. I haven’t tested it if this implies other problems.

Would be nice to have your feedback. Thank you very much for reading.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:2
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Nutomiccommented, Mar 30, 2015

The problem is that there is no constructor for IntentIntegrator that takes android.support.v4.preference.PreferenceFragment. Could you implement such a constructor?

The code in the second comment should work, but I’d rather not use that ugly hack.

1reaction
srowencommented, Jan 20, 2015

I suppose I’m asking whether the “312” is the necessary change, or calling startActivity on the Fragment? I would not expect that the value matters as long as its top 16 bits are 0 (these are reserved from Android 3.x onward IIRC). I also expect that you can use the constructor for Fragment if you need its method invoked. Do we need a different, other constructor?

Read more comments on GitHub >

github_iconTop Results From Across the Web

onActivityResult is not being called in Fragment - Stack Overflow
My fragment starts an activity for a result with the intent sent for the camera to take a picture. The picture application loads...
Read more >
IntentIntegrator with android.support.v4.Fragment calls wrong ...
Because the activity (of the fragment) is called, the result is delivered to FragmentTabsPager.onActivityResult(), and not MyFragment.onActivityResult().
Read more >
android.support.v4.app.Fragment.onActivityResult java code ...
onActivityResult() not called in new nested fragment API. @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.
Read more >
fragment/java/android/support/v4/app/FragmentActivity.java
you may not use this file except in compliance with the License. ... {@link #finish()} is called. If no entry Transition was used,...
Read more >
Wrong state after invoking startActivityForResult [65665621]
toString() }) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found