当我从图库中选择图片时,在onActivityResult之后调用android – onCreate

当我从图库中选择图片时,在onActivityResult之后调用android – onCreate,第1张

概述我有’SherlockFragmentActivity’和’onActivityResult’. 我试图从相机和画廊获取图像并裁剪它. 问题是我在onActivityResult调用后返回我的活动而不是片段. ... FragmentTransaction t = fragmentManager.beginTransaction(); LogInFr 我有’SherlockFragmentActivity’和’onActivityResult’.

我试图从相机和画廊获取图像并裁剪它.
问题是我在onActivityResult调用后返回我的活动而不是片段.

...            FragmentTransaction t = fragmentManager.beginTransaction();            LogInFragment logFrag = new LogInFragment();            t.replace(R.ID.fragment_container,logFrag);            t.commit();...     @OverrIDe        protected voID onActivityResult(int requestCode,int resultCode,Intent data) {            super.onActivityResult(requestCode,resultCode,data);        }

活动布局:

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"                androID:ID="@+ID/fragment_container"                androID:background="@color/textWhite"                androID:layout_wIDth="fill_parent"                androID:layout_height="fill_parent"></relativeLayout>

我还选择了’SherlockFragment’,我选择了图像:

startimagePickerDialog(this);public voID startimagePickerDialog() {        AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(getSherlockActivity());        myAlertDialog.setTitle("Upload Pictures Option");        myAlertDialog.setMessage("How do you want to set your picture?");        myAlertDialog.setPositivebutton("gallery",new DialogInterface.OnClickListener() {            public voID onClick(DialogInterface arg0,int arg1) {                Intent intent = new Intent();                // call androID default gallery                intent.setType("image/*");                intent.setAction(Intent.ACTION_GET_CONTENT);                // ******** code for crop image                intent.putExtra("crop","true");                intent.putExtra("aspectX",1);                intent.putExtra("aspectY",1);                intent.putExtra("outputX",200);                intent.putExtra("outputY",200);                intent.putExtra("noFaceDetection",true);                try {                    intent.putExtra("return-data",true);                    startActivityForResult(Intent.createChooser(intent,"Complete action using"),Const.galLERY_PICTURE);                } catch (ActivityNotFoundException e) {                    Log.e(LOG_TAG,"ActivityNotFoundException");                }            }        });        myAlertDialog.setNegativebutton("Camera",int arg1) {                // call androID default camera                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);                intent.putExtra(MediaStore.EXTRA_OUTPUT,MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString());                intent.putExtra("crop",true);                    startActivityForResult(intent,Const.CAMERA_REQUEST);                } catch (ActivityNotFoundException e) {                    Log.e(LOG_TAG,"ActivityNotFoundException");                }            }        });        myAlertDialog.show();    }

‘SherlockFragment’中的’onActivityResult’:

@OverrIDe    public voID onActivityResult(int requestCode,Intent data) {        Log.d(LOG_TAG,"onActivityResult");        super.onActivityResult(requestCode,data);        if (resultCode != getSherlockActivity().RESulT_OK) {            Log.e(LOG_TAG,"resultCode != RESulT_OK");            return;        }        if (requestCode == Const.CAMERA_REQUEST) {            Log.d(LOG_TAG,"requestCode == CAMERA_REQUEST");            Bundle extras = data.getExtras();            if (extras != null) {                Log.d(LOG_TAG,"extras != null");                Bitmap photo = extras.getParcelable("data");                icon.setimageBitmap(photo);            }        }        if (requestCode == Const.galLERY_PICTURE) {            Log.d(LOG_TAG,"requestCode == galLERY_PICTURE");            Bundle extras2 = data.getExtras();            if (extras2 != null) {                Log.d(LOG_TAG,"extras != null");                Bitmap photo = extras2.getParcelable("data");                icon.setimageBitmap(photo);            }        }    }

UPDATE
当我调用相机活动时,我的主要活动调用’onSaveInstanceState’,然后调用’onRestoreInstanceState’.这是一个原因吗?

解决方法 >检查“设置” – > “开发者选项” – > “不要保持活动”的旗帜. >这是androID的本质,如果你的设备需要内存它会破坏不可见的活动.因此,您必须考虑可以随时重新创建您的活动. BTW“不要保持活动”选项可以在您的设备需要内存并破坏您的后台活动时模拟您的应用程序. 总结

以上是内存溢出为你收集整理的当我从图库中选择图片时,在onActivityResult之后调用android – onCreate全部内容,希望文章能够帮你解决当我从图库中选择图片时,在onActivityResult之后调用android – onCreate所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存