0

我有两个活动 A,B

从活动 A 中,我确实打开了我的画廊,我希望当从画廊中选择图片时,它应该在活动 B 上而不是在活动 C 上。

这可能吗??

share_picture.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent choosePic = new Intent(Intent.ACTION_PICK,
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(choosePic, LOAD_IMAGE_GALLERY);

            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == LOAD_IMAGE_GALLERY && 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]);
            picturePath = cursor.getString(columnIndex);



//I  WANT TO CALL ACTIVITY B FROM HERE.. THAT AFTER THE PICTURE IS SELECTED IT SHOULD GO ON ACITIVITY B AND NOT ON A.



        }
    }

谢谢

4

3 回答 3

0

您只需要将意图从您的onActivityResult()内部传递ActivtyA到通过意图ActivityBpicturePath

ActivityA.java

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
 //Insert it once you got the picturePath through Content Resolver
 picturePath = cursor.getString(columnIndex);
 Intent forwardToB=new Intent(getApplicationContext(),ActivityB.class);
 forwardToB.putExtras("PATH",picturePath);
 startActivity(forwardToB);
 }

ActivityB.java

Intent i=getIntent();
String pathToImage=i.getStringExtra("PATH");

                OR

Bundle extras = this.getIntent().getExtras();
if (extras != null) 
{
 String value = extras.getString("PATH");
}

现在你可以做任何曾经pathToImage在你的ActivityB

于 2013-01-05T08:11:52.393 回答
0

将意图额外放入您的 filePathColumn。完成ActivityC; Activity并有意图地呼叫B;

于 2013-01-05T07:40:34.457 回答
0

onActivityResult只需在之后编写此代码picturePath = cursor.getString(columnIndex);

   // used to show HD images
  BitmapFactory.Options bounds = new BitmapFactory.Options();
  // divide bitmap to 4 sample size it can be 2rest(2,4,8 etc)
  bounds.inSampleSize = 4;
  // get bitmap from bounds and file path
  Bitmap bmp = BitmapFactory.decodeFile(filePath, bounds);
  imageView1.setImageBitmap(bmp);

现在在这里写Intent代码

  Intent intent= new Intent(A.java,B.class);
  startActivity(intent);
于 2013-01-05T07:48:00.227 回答