OnActivityResult () fragment compatibility not working

I am working on an Android application that uses the android comparison library (android-support-v4). Before SDK 20, I was able to compile my application with the following uses-sdk entry in my manifest.

 <uses-sdk android:minSdkVersion="7" /> 

All my fragments that started activity for the result got their results correctly.

One fine day (before I upgraded to SDK 20), I fixed problems with lint, and I added android:targetSdkVersion to the manifest to request the lint flag, and soon realized that none of my fragments received their onActivityResilt calls ( )

Now, when I upgrade to SDK 20.0.1, I am forced to use the android:targetSdkVersion in uses-sdk entry in my manifest; otherwise R.java is never generated.

Here is my current uses-sdk manifest entry

 <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16" /> 

Currently, due to this odd error, my application is currently still not working. I tried updating my compatible library with the latest version of r9.

I also double-checked all my startActivityForResult() calls in fragments. All of them use the corresponding calls using the fragment method.

ie

  this.startActivityForResult(intent, requestCode); 

not

  this.getActivity().startActivityForResult(intent, requestCode); 

My current development environment:

 Android SDK 20.0.1 Android SDK Platform Tools 13 ADT 20.0.2 

Any help would be greatly appreciated, as this bug is currently a brick wall that prevents my final beta tests.

EDIT

Here is my output of ant debug

$ ant debug Buildfile: / home / ricky / Development / workspace / location _ringer / LocationRinger / build.xml

-set test mode:

-SET-debug files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed in / app / android -sdk-linux_86

-setup: [echo] Project name: ListActivity [gettype] Project type: Application

-set-debug mode:

-debug-obfuscation-check:

-Build-installation: [echo] Resolution of the build task for ListActivity ... [gettarget] Project goal: Google API [gettarget] Supplier: Google Inc. [gettarget] Platform version: 4.1 [gettarget] API level:
16 [echo] ---------- [echo] Creating output directories if necessary ... [echo] ---------- [echo] Resolving dependencies for ListActivity ... [dependencies ] Library Dependencies: [Dependency] [Dependency] ------------------ [Dependency] Ordered Libraries: [Dependency] [Dependency] ---------- -------- [dependency] API <= 15: Adding annotations.jar to the classpath. [echo] ---------- [echo] Creating libraries with "debug" ...

nodeps:

-set test mode:

-SET-debug files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed in / app / android -sdk-linux_86

-setup: [echo] Project name: LocationLib [gettype] Project type: Android library

-set-debug mode:

-debug-obfuscation-check:

-Build-installation: [echo] Resolution of the build task for LocationLib ... [gettarget] Project goal: Google API [gettarget] Supplier: Google Inc. [gettarget] Platform version: 4.1 [gettarget] API level:
16 [echo] ---------- [echo] Creating output directories if necessary ... [echo] ---------- [echo] Removing dependencies for LocationLib ... [dependencies ] Library dependencies: [dependency] No libraries [dependency] [dependency] ------------------ [dependency] API <= 15: adding annotations.jar to the classpath.

-pre-builds:

-code-gen: [mergemanifest] No changes to AndroidManifest files. [echo] Processing help files ... [aidl] There are no AIDL files to compile. [echo] ---------- [echo] Processing RenderScript files ... [renderscript] There are no RenderScript files to compile. [echo] ---------- [echo] Processing resources ... [aapt] No modified resources. R.java and Manifest.java intact. [echo] ---------- [echo] Handling the BuildConfig class ... [buildconfig] No need to generate a new BuildConfig.

-pre-compilation:

-compile: [echo] Creating the jar file of the library file ...

-post-compilation:

-obfuscate:

-dex: [echo] Library project: do not convert bytecode ...

-crunch: [crunch] Crunch PNG files in the source directory: / home / ricky / Development / workspace / location_library / LocationLib / res
[crunch] To destination directory: / Home / Ricky / Development / workspace / location_library / LocationLib / bin / Res [crunch] Crunched 0 PNG files to update the cache

-package-resources: [echo] Library project: do not package resources ...

-package: [echo] Library project: don't pack apk ...

post package:

-U-debugging: [echo] Library project: do not create apk ... [propertyfile] Property file update: / home / ricky / Development / workspace / location _library / LocationLib / bin / build.prop [propertyfile] Property file update: / home / ricky / Development / workspace / location _library / LocationLib / bin / build.prop [propertyfile] Updating the properties file: / home / ricky / Development / workspace / location _library / LocationLib / bin / build.prop [propertyfile] Updating the file Properties: / home / ricky / Development / workspace / location _library / LocationLib / bin / build.prop

-post-builds:

debugging:

nodeps:

-set test mode:

-SET-debug files:

-check-env: [checkenv] Android SDK Tools Revision 20.0.1 [checkenv] Installed in / app / android -sdk-linux_86

-setup: [echo] Project name: ExceptionHandlerLib [gettype] Project type: Android library

-set-debug mode:

-debug-obfuscation-check:

-Build-installation: [echo] Resolution of the build task for ExceptionHandlerLib ... [gettarget] Project goal: Android 4.1 API level [gettarget]:
16 [echo] ---------- [echo] Creating output directories if necessary ... [echo] ---------- [echo] Resolving dependencies for ExceptionHandlerLib ... [dependencies ] Library dependencies: [dependency] No libraries [dependency] [dependency] ------------------ [dependency] API <= 15: Adding annotations.jar to the classpath.

-pre-builds:

-code-gen: [mergemanifest] No changes to AndroidManifest files. [echo] Processing help files ... [aidl] There are no AIDL files to compile. [echo] ---------- [echo] Processing RenderScript files ... [renderscript] There are no RenderScript files to compile. [echo] ---------- [echo] Processing resources ... [aapt] No modified resources. R.java and Manifest.java intact. [echo] ---------- [echo] Handling the BuildConfig class ... [buildconfig] No need to generate a new BuildConfig.

-pre-compilation:

-compile: [echo] Creating the jar file of the library file ...

-post-compilation:

-obfuscate:

-dex: [echo] Library project: do not convert bytecode ...

-crunch: [crunch] Crunch PNG files in the source directory: / home / ricky / Development / workspace / exception_handler_library / ExceptionHandlerLib / res [crunch] To the destination directory: / Home / Ricky / Development / workspace / exception_handler_library / ExceptionHandlerLib / bin / Res [crunch] Crunched 0 PNG files to update the cache

-package-resources: [echo] Library project: do not package resources ...

-package: [echo] Library project: don't pack apk ...

post package:

-U-debugging: [echo] Library project: do not create apk ... [propertyfile] Updating the property file: / home / ricky / Development / workspace / exception _handler_library / ExceptionHandlerLib / bin / build.prop [propertyfile] Updating the properties file: / home / ricky / Development / workspace / exception _handler_library / ExceptionHandlerLib / bin / build.prop [propertyfile] Updating the properties file: / home / ricky / Development / workspace / exception _handler_library / ExceptionHandlerLib / bin / build.prop [propertyfile] Updating the file properties: / home / ricky / Development / workspace / exception _handler_library / ExceptionHandlerLib / bin / build.prop

-post-builds:

debugging:

-pre-builds:

-code-gen: [mergemanifest] Combine AndroidManifest files into one. [mergemanifest] Combines project manifests and 2 libraries. [mergemanifest] Warning: [AndroidManifest.xml: 3, AndroidManifest.xml: 3] The main manifest has, but the library uses targetSdkVersion = '16 '[mergemanifest] Note: there is no declaration in the main manifest whose default value is minSdkVersion or 1. [ mergemanifest] Warning: [AndroidManifest.xml: 3, AndroidManifest.xml: 13] The main manifest has, but the library uses targetSdkVersion = '16 '[mergemanifest] Note: there is no declaration in the main manifest whose default value is minSdkVersion or 1.

BUILD FAILED / app / android-sdk-linux_86 / tools / ant / build.xml: 616: null

Total time: 2 seconds

EDIT

I looked through /app/android-sdk-linux_86/tools/ant/build.xml:616 and found that the next line selected the null value enabled="${manifestmerger.enabled}">

here is the whole block

I will try to disable the manifest merge option and see what happens

EDIT

It would seem that removing manifestmerger.enabled = true from project.properties solved my problem. The project now compiles and works fine. I think I should report this error to the android team. My manifest has the following entry

 <uses-sdk android:minSdkVersion="7" /> 

However, onActivityResult () is still not called if I raise targetSdkVersion above 7, so this doesn’t really solve the root problem, but my project is now working fine

+6
source share
5 answers

It would seem that removing manifestmerger.enabled = true from project.properties solved my problem. The project now compiles and works fine. I think I should report this error to the android team. My manifest has the following entry

 <uses-sdk android:minSdkVersion="7" /> 

However, onActivityResult () is still not called if I raise targetSdkVersion above 7, so this doesn’t really solve the root problem, but my project is now working fine

0
source

In fragment (False startActivityForResult)

 getActivty().startActivityForResult(intent, requestCode); // Cannot receive in fragment 

In fragment ( Fix startActivityForResult)

 startActivityForResult(intent, requestCode); // use Fragment.startActivityForRusult() // not Activity.startActivityForRusult() 

In action

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); } 

In fragment

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Do Action } 
+6
source

Here are some suggestions:

  • If you just want the manifest to not have android:targetSdkVersion , you can right-click your project in the Project Explorer in Eclipse and select Android Tools > Clear Lint Markers .

  • Make sure that all your Fragment and Activity advanced classes extend the correct classes from the compatibility library ( android.support.v4.app.Fragment and android.support.v4.app.FragmentActivity ), and none of them accidentally extends them into framework ( android.app.Fragment and android.app.Activity ).

In addition, it seems strange to me that your project does not compile if you install targetSdkVersion on anything other than 16. Is there any specific problem indicated in the "Problems / Console / Lint" window? Also check if you have another goal and / or is selected as Project Build Target (right-click the project, Properties > Android ).

+2
source

There is an error in the compatibility package (see this and this )

0
source

After downloading the latest ADT, make sure you also overwrite your support bank in your project with this:

android-sdk\extras\android\support\v4\android-support-v4.jar

Perhaps you are using an old jar when working with the latest ADT.

Otherwise, I would expect your fragments to not receive their onActivityResult () calls if the parent activity did not super.onActivityResult(requestCode, resultCode, data);

EDIT

Explicitly adding this was necessary for my project:

 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dualPane); fragment.onActivityResult(requestCode, resultCode, data); } 
0
source

Source: https://habr.com/ru/post/921690/


All Articles