android – 片段兼容性onActivityResult()不起作用

android – 片段兼容性onActivityResult()不起作用,第1张

概述我一直在研究一个利用 android可比性库( android-support-v4)的android应用程序.在SDK 20之前,我能够在清单中使用以下uses-sdk条目编译我的应用程序. <uses-sdk android:minSdkVersion="7" /> 我开始为结果活动的所有片段都能正确地获得结果. 有一天(在我更新到SDK 20之前)我正在修复lint问题,并且我根据lint标 我一直在研究一个利用 android可比性库( android-support-v4)的androID应用程序.在SDK 20之前,我能够在清单中使用以下uses-sdk条目编译我的应用程序.
<uses-sdk androID:minSdkVersion="7" />

我开始为结果活动的所有片段都能正确地获得结果.

有一天(在我更新到SDK 20之前)我正在修复lint问题,并且我根据lint标志的请求将manifest:targetSdkVersion添加到清单中,我很快意识到我的所有片段都没有接收到他们的onActivityResilt()调用.

现在每次我更新到SDK 20.0.1后,我都被迫在清单中的uses-sdk条目中使用androID:targetSdkVersion;否则R.java永远不会生成.

这是我当前的uses-sdk清单条目

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

目前由于这个奇怪的错误,我的应用程序目前仍然被打破.
我试过更新我的兼容库最新版本r9.

此外,我已经仔细检查了片段中的所有startActivityForResult()调用.他们都通过片段的方法使用正确的调用.

this.startActivityForResult(intent,requestCode);

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

我目前的开发环境:

AndroID SDK 20.0.1AndroID SDK Platform Tools 13ADT 20.0.2

任何帮助将不胜感激,因为这个BUG目前是阻止我最终beta测试的砖墙.

编辑

这是我的ant deBUG输出

$ant deBUG
Buildfile:
/home/ricky/Development/workspace/location_ringer/LocationRinger/build.xml

-set-mode-check:

-set-deBUG-files:

-check-env: [checkenv] AndroID SDK Tools Revision 20.0.1 [checkenv] Installed at /app/androID-sdk-linux_86

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

-set-deBUG-mode:

-deBUG-obfuscation-check:

-build-setup:
[echo] Resolving Build Target for ListActivity… [gettarget] Project Target: Google Apis [gettarget] vendor: Google
Inc. [gettarget] Platform Version: 4.1 [gettarget] API level:
16
[echo] ———-
[echo] Creating output directorIEs if needed…
[echo] ———-
[echo] Resolving DependencIEs for ListActivity… [dependency] library dependencIEs: [dependency] [dependency] ——————
[dependency] Ordered librarIEs: [dependency] [dependency]
—————— [dependency] API<=15: Adding annotations.jar to the classpath.
[echo] ———-
[echo] Building librarIEs with ‘deBUG’…

nodeps:

-set-mode-check:

-set-deBUG-files:

-check-env: [checkenv] AndroID SDK Tools Revision 20.0.1 [checkenv] Installed at /app/androID-sdk-linux_86

-setup:
[echo] Project name: Locationlib [gettype] Project Type: AndroID library

-set-deBUG-mode:

-deBUG-obfuscation-check:

-build-setup:
[echo] Resolving Build Target for Locationlib… [gettarget] Project Target: Google Apis [gettarget] vendor: Google
Inc. [gettarget] Platform Version: 4.1 [gettarget] API level:
16
[echo] ———-
[echo] Creating output directorIEs if needed…
[echo] ———-
[echo] Resolving DependencIEs for Locationlib… [dependency] library dependencIEs: [dependency] No librarIEs [dependency]
[dependency] —————— [dependency] API<=15: Adding
annotations.jar to the classpath.

-pre-build:

-code-gen: [mergemanifest] No changes in the AndroIDManifest files.
[echo] Handling aIDl files…
[aIDl] No AIDL files to compile.
[echo] ———-
[echo] Handling RenderScript files… [renderscript] No RenderScript files to compile.
[echo] ———-
[echo] Handling Resources…
[aapt] No changed resources. R.java and Manifest.java untouched.
[echo] ———-
[echo] Handling BuildConfig class… [buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
[echo] Creating library output jar file…

-post-compile:

-obfuscate:

-dex:
[echo] library project: do not convert bytecode…

-crunch: [crunch] Crunching PNG files in source dir: /home/ricky/Development/workspace/location_library/Locationlib/res
[crunch] To destination dir:
/home/ricky/Development/workspace/location_library/Locationlib/bin/res
[crunch] Crunched 0 PNG files to update cache

-package-resources:
[echo] library project: do not package resources…

-package:
[echo] library project: do not package apk…

-post-package:

-do-deBUG:
[echo] library project: do not create apk… [propertyfile] Updating property file:
/home/ricky/Development/workspace/location_library/Locationlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/location_library/Locationlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/location_library/Locationlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/location_library/Locationlib/bin/build.prop

-post-build:

deBUG:

nodeps:

-set-mode-check:

-set-deBUG-files:

-check-env: [checkenv] AndroID SDK Tools Revision 20.0.1 [checkenv] Installed at /app/androID-sdk-linux_86

-setup:
[echo] Project name: ExceptionHandlerlib [gettype] Project Type: AndroID library

-set-deBUG-mode:

-deBUG-obfuscation-check:

-build-setup:
[echo] Resolving Build Target for ExceptionHandlerlib… [gettarget] Project Target: AndroID 4.1 [gettarget] API level:
16
[echo] ———-
[echo] Creating output directorIEs if needed…
[echo] ———-
[echo] Resolving DependencIEs for ExceptionHandlerlib… [dependency] library dependencIEs: [dependency] No librarIEs
[dependency] [dependency] —————— [dependency] API<=15:
Adding annotations.jar to the classpath.

-pre-build:

-code-gen: [mergemanifest] No changes in the AndroIDManifest files.
[echo] Handling aIDl files…
[aIDl] No AIDL files to compile.
[echo] ———-
[echo] Handling RenderScript files… [renderscript] No RenderScript files to compile.
[echo] ———-
[echo] Handling Resources…
[aapt] No changed resources. R.java and Manifest.java untouched.
[echo] ———-
[echo] Handling BuildConfig class… [buildconfig] No need to generate new BuildConfig.

-pre-compile:

-compile:
[echo] Creating library output jar file…

-post-compile:

-obfuscate:

-dex:
[echo] library project: do not convert bytecode…

-crunch: [crunch] Crunching PNG files in source dir: /home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/res
[crunch] To destination dir:
/home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/bin/res
[crunch] Crunched 0 PNG files to update cache

-package-resources:
[echo] library project: do not package resources…

-package:
[echo] library project: do not package apk…

-post-package:

-do-deBUG:
[echo] library project: do not create apk… [propertyfile] Updating property file:
/home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/bin/build.prop
[propertyfile] Updating property file:
/home/ricky/Development/workspace/exception_handler_library/ExceptionHandlerlib/bin/build.prop

-post-build:

deBUG:

-pre-build:

-code-gen: [mergemanifest] Merging AndroIDManifest files into one. [mergemanifest] Merging manifests from project and 2 librarIEs.
[mergemanifest] Warning: [AndroIDManifest.xml:3,
AndroIDManifest.xml:3] Main manifest has but library uses targetSdkVersion=’16’
[mergemanifest] Note: main manifest lacks a declaration,which defaults to value
minSdkVersion or 1. [mergemanifest] Warning: [AndroIDManifest.xml:3,
AndroIDManifest.xml:13] Main manifest has but library uses targetSdkVersion=’16’
[mergemanifest] Note: main manifest lacks a declaration,which defaults to value
minSdkVersion or 1.

BUILD Failed /app/androID-sdk-linux_86/tools/ant/build.xml:616: null

Total time: 2 seconds

编辑

我查看了/app/androID-sdk-linux_86/tools/ant/build.xml:616,发现以下行抛出了null enabled =“${manifestmerger.enabled}”>

这是整个街区


我将尝试禁用清单合并选项,看看会发生什么

编辑

似乎从project.propertIEs中删除manifestmerger.enabled = true已经解决了我的问题.该项目现在编译并完美运行.我想我应该把这个BUG报告给androID团队.我的清单有以下条目

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

但是如果我将targetSdkVersion提高到7以上仍然没有调用onActivityResult(),所以这并没有真正解决root问题,但我的项目现在正常工作

解决方法 在Fragment中(错误的startActivityForResult)
getActivty().startActivityForResult(intent,requestCode); // Cannot receive in fragment

在Fragment中(正确的startActivityForResult)

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

在活动中

@OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data) {    super.onActivityResult(requestCode,resultCode,data);}

在片段中

@OverrIDeprotected voID onActivityResult(int requestCode,Intent data) {    // Do Action}
总结

以上是内存溢出为你收集整理的android – 片段兼容性onActivityResult()不起作用全部内容,希望文章能够帮你解决android – 片段兼容性onActivityResult()不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1130855.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存