android - Android 8.1 在调用 startActivityForResult() 时关闭 Activity
问题描述
有人来救我。我正在构建一个需要从设备相机拍照并将缩略图加载到 ImageView 的 android 应用程序,请注意我不想保存此图像,我只想将其加载到 ImageView 并从ImageView 稍后。
这就是我已经实现的:启动相机:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(cameraIntent.resolveActivity(activityWeakReference.get().getPackageManager()) != null){
startActivityForResult(cameraIntent, UPLOAD_PICTURE_CAMERA);
}
onActivityResult(int requestCode, int resultCode, Intent data)
调用时调用以下内容startActivityForResult()
:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK && requestCode == UPLOAD_PICTURE_CAMERA) {
try{
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
imageViewphoto.setImageBitmap(imageBitmap);
}catch (Exception e){
Log.e(TAG, Utility.stringify(e));
}
}
问题:上面的代码在 android 7.0 上运行良好,但在 Oreo 8.1 上,活动在相机打开后立即关闭,因此onActivityResult()
不会被调用。
这是我能得到的所有日志:
I/PhoneWindow: isNeedChangeStatusBarColor taskInfo: [android.app.ActivityManager$RunningTaskInfo@c7a24ee] size: 1
isAPPNeedChangeSBColor pkgName: com.a3lineng.softwaredev.freedom_app needKeep: false
isNeedChangeStatusBarColor false
I/PhoneWindow: isNeedChangeNaviBarColor taskInfo: [android.app.ActivityManager$RunningTaskInfo@5566d8f] size: 1
I/PhoneWindow: isAPPNeedChange pkgName: com.a3lineng.softwaredev.freedom_app needKeep: false
isNeedChangeNaviBarColor false
generateLayout mNavigationBarColor: ff000000
I/PhoneWindow: generateLayout isLightNavi false, Visibility: 0
I/zygote: Do full code cache collection, code=505KB, data=398KB
I/zygote: After code cache collection, code=495KB, data=332KB
D/BaseActivity: On Pause is called
I/zygote: Do partial code cache collection, code=505KB, data=341KB
I/zygote: After code cache collection, code=505KB, data=341KB
Increasing code cache capacity to 2MB
D/BaseActivity: On Stop is called
Disconnected from the target VM, address: 'localhost:8857', transport: 'socket'
谁在奥利奥面临同样的问题?,任何建议将不胜感激。
解决方案
在我的情况下,我已经能够弄清楚这一点,我发现它是在设备上启用的名为 Kill Background Activities 的用户设置。我所做的只是取消选中它,调用活动可用于接收来自相机意图的结果。
感谢您的帮助。
推荐阅读
- json - 在powershell中重新排序对象成员
- android-studio - 如何在 Android Studio 上打开 Activity_main.xml
- clojurescript - 如何在 Reagent 中编辑 Reitit 路由?
- node.js - 使用节点获取的 Firebase 函数返回证书错误
- javascript - 使用 JQuery .load() 将 JSON 数据发送到 Flask 服务器
- embedded - STM32 EEPROM 仿真与 HAL_FLASH 和 HAL_FLASH_EX 驱动程序
- java - 如何使用 UssdResponseCallback 和 sendUssdRequest?
- ios - 如何从 swift Xcode 中的不同类更改 UISwitch 的值?
- excel - WorkbookOpen 事件有时不会触发 - 用于设置全局变量的事件
- python - 这些词的意思是一样的吗?