在Gallery意图的情况下如何使用onConfigurationChanged?

时间:2013-02-23 05:54:23

标签: android android-gallery

在我的应用程序中,我为用户提供了从图库中选择图片或从相机中单击它的选项,使用内置的相机和图库功能并设置相同的意图。以某种方式改变方向我失去了从这些意图传递的数据。在查找之后,我开始知道方向更改会导致活动重绘并重新初始化。现在我想使用Bundle和OnConfigurationChange并保存我的额外内容。我对如何实现它一无所知,详细的答案可能会有所帮助。以下是我的代码:

if(i==0){
    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); 
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if( requestCode == 1337 && resultCode== Activity.RESULT_OK) {
        Bundle extras = data.getExtras();

        if (extras != null){
            TitmapFactory.Options options = new TitmapFactory.Options();
            options.inSampleSize = 1;
            options.inPurgeable = true;
            options.inInputShareable = true;
            thumbnail = (Titmap) data.getExtras().get("data");
            // imgview.setImageTitmap(thumbnail);
            image(thumbnail);

        } else {
            Toast.makeText(CreateProfile.this, "Picture NOt taken", Toast.LENGTH_LONG).show();
        }
        super.onActivityResult(requestCode, resultCode, data);     
    }
}






     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data){

         Uri selectedImage = data.getData();

            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            thumbnail = (BitmapFactory.decodeFile(picturePath));



            image(thumbnail);

     }

0 个答案:

没有答案