Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onActivityResult (int requestCode, int resultCode, Intent intent) is not called inside fragments #3

Closed
Whyser opened this issue Jan 16, 2015 · 5 comments
Labels

Comments

@Whyser
Copy link

Whyser commented Jan 16, 2015

The onActivityResult is never called in Fragments, it's only called in a fragments parent Activity. At the moment I have to forward the onActivityResult to the correct Fragment as seen below:

@Override
public void onActivityResult (int requestCode, int resultCode, Intent intent) {
   if(mFragment != null) 
       mFragment.onActivityResult(requestCode, resultCode, intent);
}
@ocram ocram added the bug label Jan 17, 2015
@ocram
Copy link
Contributor

ocram commented Jan 17, 2015

Thank you so much!

This commit should introduce support for Fragments:
7e262ed

The README has been updated as well to include the how-to for fragments.

However, this might not work yet if you're using the "v4" support library. Can you try?

@ocram ocram closed this as completed Jan 24, 2015
@splitbrain
Copy link

This seems not to work with the v4 support lib. My Fragment is not even recognized as Fragment by the AdvancedWebView constructor. I had to use it with getActivity() and forward the activity result as suggested by @Whyser

@ocram
Copy link
Contributor

ocram commented Jul 15, 2015

Thanks for checking this and pointing out the problem, @splitbrain!

Right now, this library only supports ..

  • simple Activity instances without fragments
  • fragment-based Activity instances that use the normal Android Fragment class

Unfortunately, android.app.Fragment and android.support.v4.app.Fragment are two completely separate classes. Naturally so, as the latter was included in the "Android Support Library v4" specifically for those apps that need to run on devices prior to API level 11 (where there is no Fragment class, normally).

So without including the support library in this library as well, it does not know that android.support.v4.app.Fragment exists at all.

To avoid including the support library in this project (and always keeping it in sync with the latest version), you can circumvent the problem in one of the following ways:

  • Drop support for API levels prior to 11 (5.9% of all users) and use android.app.Fragment instead of android.support.v4.app.Fragment
  • Don't include this library as a JAR but by copying the source code. Include it in your app's source code directly, include the support library (you have already done this) and then change the references from android.app.Fragment to android.support.v4.app.Fragment
  • Keep using getActivity() and forwarding the result. Is this acceptable?

Maybe we could even include a package named android.support.v4.app with an empty class Fragment in this library. So this library would know that the class exists and when you include the support library in your app (with the right build order?), it overrides our android.support.v4.app.Fragment with the correct one. Don't know if that will work, however.

Does that help?

@splitbrain
Copy link

splitbrain commented Jul 15, 2015 via email

@ocram
Copy link
Contributor

ocram commented Aug 12, 2015

The documentation has been updated to include instructions regarding the support library:
b92588a

Hopefully, this description is okay and matches the solution you two have found, @Whyser and @splitbrain.

Thank you!

@1170762202 1170762202 mentioned this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants