Android - Wie kann ich ImageView von einer Aktivität auf eine andere Aktivität übertragen?

Ich habe Activity1, die ein ImaveView einschließlich Bildvorschau haben. Sobald ich den Knopf drücke, gehe ich von Activity1 zu Activity2. In Activity2 habe ich keine Bildvorschau, sondern ein Optionsfeld "Bild von Activit1 speichern?" Ja oder Nein.

Momentan mache ich es falsch, als würde man das Image auf der Festplatte speichern und dann von der Festplatte zurücklesen. Aber gibt es eine Möglichkeit, ohne das Bild zu speichern, kann ich eine Bildansicht von Activity1 zu Activity2 übertragen?

So bekomme ich das Bild in meiner Activity1> ImageView, das dann in Activity2 verschoben werden muss. Irgendeine Idee?

public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      this.imageView = (ImageView)this.findViewById(R.id.picture);            
      Button photoButton = (Button) this.findViewById(R.id.capture_btn);      
      Button btnShareToEmail = (Button) this.findViewById(R.id.btnshare);
      btnShareToEmail.setOnClickListener(this);

      //photoButton.setOnClickListener(new View.OnClickListener() {
          //@Override
        //  public void onClick(View v) {
          //    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
            //  startActivityForResult(cameraIntent, CAMERA_REQUEST); 
         // }
      //});

      // without frozen
      new Handler().postDelayed(new Runnable() { public void run() { 
          Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
          startActivityForResult(cameraIntent, CAMERA_REQUEST);
      }}, 100);      
  }



  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);



    }  
  }

BEARBEITEN:

// Setze - Aktivität1

Intent winShare = new Intent(getBaseContext(), Activity2.class);
winShare.putExtra("Title", "r2.jpg");
winShare.putExtra("image1", photo);         
//int image_link = getIntent().getIntExtra("image1");
startActivityForResult(winShare,0); 

// GET - Aktivität2

    Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("image1"); // BITMAP_SHARED_KEY = "bitmap_shared_key"

    imageView.setImageBitmap(bitmap);
    // save it
    imageView.buildDrawingCache();
    Bitmap bm=imageView.getDrawingCache();
    OutputStream fOut = null;
    Uri outputFileUri;
    try {
      File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MYAPPPPPPPPPS" + File.separator);
      root.mkdirs();
      File sdImageMainDirectory = new File(root, "myPicName.jpg");
      outputFileUri = Uri.fromFile(sdImageMainDirectory);
      fOut = new FileOutputStream(sdImageMainDirectory);
      bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
      fOut.flush();
      fOut.close();      
   } catch (Exception e) {
     Toast.makeText(this, "Error occured. Please try again later.",Toast.LENGTH_SHORT).show();
   }

Antworten auf die Frage(3)

Ihre Antwort auf die Frage