Accessing Gallery pics in android
<p>I'm trying to get my gallery pics in my program. And I'm able to do to same by using following code:</p>

<p>To open gallery:</p>

<pre><code>Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent,1); 
</code></pre>

<p>and to get result back and display selected image:</p>

<pre><code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) 
{ 
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent); 

    switch(requestCode) 
    { 
    case SELECT_PHOTO:
        if(resultCode == RESULT_OK)
        {  
            Uri selectedImage = imageReturnedIntent.getData();
            InputStream imageStream = null;
            try 
            {
                imageStream = getContentResolver().openInputStream(imageReturnedIntent.getData());
            } 
            catch (FileNotFoundException e) 
            {
                e.printStackTrace();
            }
            selectedContactPicture = BitmapFactory.decodeStream(imageStream);
            setContactPicture.setBackgroundDrawable(new BitmapDrawable(selectedContactPicture));
        }
    }
}
</code></pre>

<p>Its working fine for the first time. But if I'm selecting another picture from my gallery my app getting crashed. Please help me guys to resolve this problem.</p>

<p>Logcat:</p>

<pre><code>05-08 10:45:12.180: E/AndroidRuntime(16782): FATAL EXCEPTION: main
05-08 10:45:12.180: E/AndroidRuntime(16782): java.lang.OutOfMemoryError
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:555)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at com.deepsa.apps.callfaker.MainActivity.onActivityResult(MainActivity.java:89)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.Activity.dispatchActivityResult(Activity.java:4649)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2996)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3043)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.ActivityThread.access$1100(ActivityThread.java:127)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1188)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.os.Looper.loop(Looper.java:137)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at android.app.ActivityThread.main(ActivityThread.java:4441)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at java.lang.reflect.Method.invoke(Method.java:511)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
05-08 10:45:12.180: E/AndroidRuntime(16782):    at dalvik.system.NativeStart.main(Native Method)
</code></pre>

<p>Thanks</p>
