Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid how to open image and display it in second activity
    primarykey
    data
    text
    <p>I am working on app for editing photos</p> <p>I have a button in first activity and ImageView in second activity. When I click the button it would open gallery and I would be able to select an image. The selected image needs to appear in my ImageView in second activity but it doesn't.</p> <p>Down below is my code which is not working,have you any idea what is wrong?</p> <p><strong>FIRST ACTIVITY:</strong></p> <pre><code>package com.example.odabirslike; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.ImageView; public class Pocetni extends Activity { private Button buttonLoadImage; private static final int SELECT_PICTURE = 1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pocetni); this.buttonLoadImage = (Button) this.findViewById(R.id.pickbutton); buttonLoadImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Intent i = new Intent(); i.setType("image/*"); i.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(i, "Complete action using"), SELECT_PICTURE); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { Bitmap selectedphoto = null; super.onActivityResult(requestCode, resultCode, data); if (requestCode == SELECT_PICTURE &amp;&amp; resultCode == RESULT_OK &amp;&amp; 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 filePath = cursor.getString(columnIndex); selectedphoto = BitmapFactory.decodeFile(filePath); cursor.close(); Intent i = new Intent (Pocetni.this, Drugi.class); i.putExtra("data",selectedphoto); startActivity(i); } } } </code></pre> <p>SECOND ACTIVITY:</p> <pre><code>package com.example.odabirslike; import android.os.Bundle; import android.app.Activity; import android.graphics.Bitmap; import android.view.Menu; import android.widget.ImageView; public class Drugi extends Activity { ImageView view = (ImageView) findViewById(R.id.imageView1); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drugi); Bitmap selectedphoto =(Bitmap)this.getIntent().getParcelableExtra("data"); view.setImageBitmap(selectedphoto); } } </code></pre> <p>ANDROID MANIFEST:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.odabirslike" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt; &lt;uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.odabirslike.Pocetni" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name="com.example.odabirslike.Drugi" android:label="Drugi" &gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload