I'm an Android newbie. I'm trying to pass data from one activity to another. The data is of type List. It is received properly by the recieving activity. However I'm unable to make a string array out of it. What am I doing wrong?
This is the transmitting activity
List<String> where = new ArrayList<String>();
intent.putStringArrayListExtra("tokeo", (ArrayList<String>) where);
startActivity(intent);
The first log statement correctly prints what I expect it to. However the toast and the subsequent log message print a hex address value.
The full code for the reciever is as follows. I am using this with the Android Universal Image Loader. When I use type String for imageURLs, I get a problem with imageUrls.length & imageUrls[position].
public class PrimaryImageGridActivity extends AbsListViewBaseActivity {
DisplayImageOptions options;
String imageUrls;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_primary_image_grid);
Intent i = getIntent();
// getting attached intent data
ArrayList<String> tokeo = i.getStringArrayListExtra("tokeo");
Log.i("Shades", "We got " + tokeo);
//imageUrls = new String[tokeo.size()];
imageUrls = tokeo.toString();
//String[] result = i.getStringExtra("tokeo");
Toast.makeText(getApplicationContext(), "We have " + imageUrls,
Toast.LENGTH_LONG).show();
Log.i("Shades", "We got " + imageUrls);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error).cacheInMemory(true)
.cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(this));
listView = (GridView) findViewById(R.id.gridview);
((GridView) listView).setAdapter(new ImageAdapter());
}
/*
* @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the
* menu; this adds items to the action bar if it is present.
* getMenuInflater().inflate(R.menu.primary_image_grid, menu); return true;
* }
*/
public class ImageAdapter extends BaseAdapter {
@Override
public int getCount() {
return imageUrls.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView imageView;
if (convertView == null) {
imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
} else {
imageView = (ImageView) convertView;
}
imageLoader.displayImage(imageUrls[position], imageView, options);
return imageView;
}
}
}
Looking at some other posts on this site, I tried the following:
int s = tokeo.size();
imageUrls = new String[s];
for(int k=0; k < s; k++){
imageUrls[k] = tokeo.get(k);
Log.i("test", "We got " + tokeo.get(k));
Log.i("and", "We got " + imageUrls[k]);
}
Log.i("Shades", "We got " + imageUrls);
Each element of imageUrls prints perfectly in the loop. Once I exit the loop, it prints a hex address again.