[英]Android 8.1 Closes Activity when startActivityForResult() is called
有人來救我。 我正在構建一個Android應用程序,需要從設備相機拍攝照片並將縮略圖加載到ImageView中,請注意我不想保存此圖像,我只想將其加載到ImageView中並從中獲取位圖ImageView以后。
這就是我已經實現的:啟動相機:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if(cameraIntent.resolveActivity(activityWeakReference.get().getPackageManager()) != null){
startActivityForResult(cameraIntent, UPLOAD_PICTURE_CAMERA);
}
下面是調用startActivityForResult()
時調用的onActivityResult(int requestCode, int resultCode, Intent data)
:
@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上,活動立即關閉Camera打開,因此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'
誰在Oreo面臨同樣的問題?,任何建議都將受到贊賞。
我已經能夠在我的情況下解決這個問題,我發現它是在設備上啟用的名為Kill Background Activities的用戶設置。 我所做的只是取消選中它,並且調用活動可用於從Camera意圖接收結果。
謝謝你的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.