Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this with many way. simple is with intent. but it may hang your device and it also give you out of memory Exception in many device like Galaxy S3.</p> <p>so i ll give you very simple way see below.</p> <p>you can create <code>static</code> variable in one class like :</p> <pre><code>public class ABC{ public static Bitmap PHOTO = null; } </code></pre> <p>now when you get bitmap from gallery or any other way then you have to save bitmap in this PHOTO variable.(this is possible in only onActivityResult, am i right?)</p> <p>if you get photo from camera then code is.</p> <pre><code>Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAMERA_PIC_REQUEST); </code></pre> <p>and,</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK) { switch (requestCode) { case CAMERA_PIC_REQUEST: Bitmap b = (Bitmap) data.getExtras().get("data"); if (b != null) { ABC.PHOTO = b; } break; } } </code></pre> <p>and use this PHOTO variable in any other Activity.</p> <p>you can use this same way when pick photo from gallery.</p> <hr> <p>hi this is edited ans.</p> <p>this is just sample example of grid view. here you get idea about how pass image from one activity to another.</p> <p>this is your main Activity class:</p> <pre><code>package com.GridViewDemo; import java.io.InputStream; import java.net.URL; import java.util.GregorianCalendar; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.ImageView; public class GridViewDemoActivity extends Activity { /** Called when the activity is first created. */ // String[] mArr = // {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; String[] mArr = { "http://www.xda-developers.com/wp-content/uploads/2012/10/androidfigure.jpg?f39ce1", "http://1.bp.blogspot.com/-Ramp-o0Cp8s/T0VafXkE4uI/AAAAAAAAAQU/i703zg5MBgI/s1600/android-wallpaper5_1024x768.jpg", "http://www.thebiblescholar.com/android_awesome.jpg", "http://blogs-images.forbes.com/rogerkay/files/2011/07/Android1.jpg" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GridView gridView = (GridView) findViewById(R.id.gridView1); gridView.setAdapter(new ImageAdapter(this)); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub /** if you have bitmap here then you can use this way * Bitmap bitmap = getBitmap(); * test.PHOTO = bitmap; * * */ Intent i = new Intent(GridViewDemoActivity.this, newActiivty.class); i.putExtra("Image_Path", ""+mArr[arg2]); startActivity(i); } }); } public class ImageAdapter extends BaseAdapter { private Context mContext; public ImageAdapter(Context c) { mContext = c; } @Override public int getCount() { // TODO Auto-generated method stub return mArr.length; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ImageView imgView; if (convertView == null) { imgView = new ImageView(mContext); imgView.setLayoutParams(new GridView.LayoutParams(85, 85)); imgView.setScaleType(ImageView.ScaleType.CENTER_CROP); imgView.setPadding(8, 8, 8, 8); } else { imgView = (ImageView) convertView; } Drawable d = LoadImageFromWebOperations(mArr[position]); if (d == null) { imgView.setImageResource(R.drawable.icon); } else { imgView.setImageDrawable(d); } return imgView; } } public static Drawable LoadImageFromWebOperations(String url) { try { InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { return null; } } } </code></pre> <p>main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;GridView android:id="@+id/gridView1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:numColumns="4"&gt;&lt;/GridView&gt; &lt;/LinearLayout&gt; </code></pre> <p>newActivity.class</p> <pre><code>package com.GridViewDemo; import java.io.InputStream; import java.net.URL; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ImageView; public class newActiivty extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.new_layout); String image_path = getIntent().getStringExtra("Image_Path"); ImageView imageview = (ImageView) findViewById(R.id.imageView1); Drawable d = LoadImageFromWebOperations(image_path); if (d != null) { imageview.setImageDrawable(d); } else { imageview.setImageResource(R.drawable.icon); } /** if you have bitmap then * imageview.setImageBitmap(test.PHOTO); * */ } public static Drawable LoadImageFromWebOperations(String url) { try { InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { return null; } } } </code></pre> <p>new_layout.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;ImageView android:src="@drawable/icon" android:id="@+id/imageView1" android:layout_width="fill_parent" android:layout_height="320dp"&gt;&lt;/ImageView&gt; &lt;/LinearLayout&gt; </code></pre> <p>manifest file</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.GridViewDemo" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="3" /&gt; &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".GridViewDemoActivity" 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=".newActiivty"&gt;&lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>this is extra class: if you have bitmap then use this way:</p> <pre><code>package com.GridViewDemo; import android.graphics.Bitmap; public class test { public static Bitmap PHOTO = null; } </code></pre> <p>i comment in code so, check it and if you have query then comment below this ans.</p>
    singulars
    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.
    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