I am trying to make an App that have 2 Activities. Activity1 is a gallery can call Activity2. Activity2 is a camera app that capture images then send these images to Activity1 and Activity1 will show these images in gallery.I can't send images between two Activities.
This code is my gallery in Activity1. I know SerializebleBitmap but in my code how can I put it in the gallery list? Here is my code:
public class HelloGallery extends Activity {
private Gallery gallery;
private ImageView imgView;
private Button btn;
private static final int SHOW_SUB_FORM = 0;
private String[] imglist;
Bundle extras = getIntent().getExtras();
private Integer[] mImageIds = {
R.drawable.sample_0,
R.drawable.sample_1,
R.drawable.sample_2,
R.drawable.sample_3,
R.drawable.sample_4,
R.drawable.sample_5,
R.drawable.sample_6,
R.drawable.sample_7
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
imgView = (ImageView)findViewById(R.id.ImageView01);
imgView.setImageResource(mImageIds[0]);
btn = (Button) findViewById(R.id.Takept);
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
btn_onClick();
}
});
if (extras != null){
String[] imglist= extras.getStringArray("IMAGE_LIST");
imgView.setImageResource(mImageIds[0]);
}
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
imgView.setImageResource(mImageIds[position]);
}
});
};
private void btn_onClick() {
Intent intent = new Intent(HelloGallery.this,CameraDemo.class);
startActivity(intent);
}
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(mImageIds[position]);
imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundResource(mGalleryItemBackground);
return imageView;
}
}
}