0

I have a listview with text and images from web with JSON (works fine) and when I click on that I want to go to a DetailActivity with some TextViews and the ImageView from list. I can pass all the Textviews from the ListActivity to the DetailActivity but not the ImageView.

I tried to pass the bitmap with putextras and model but nothing. How can approach that issue? Can I call the bitmap from cache direct to the DetailActivity?

halfer
  • 19,824
  • 17
  • 99
  • 186
gas
  • 13
  • 6

4 Answers4

1

You can use ImageLoader

  Intent i = getIntent();
     // Get the result of flag
    flag = i.getStringExtra("flag"); // image 

    // Locate the TextViews and images in singleitemview.xml
    ImageView imgflag = (ImageView) findViewById(R.id.flag);
    imageLoader.DisplayImage(flag, imgflag); // use lazylist image loader

You can see this example.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shadow
  • 6,864
  • 6
  • 44
  • 93
0

Did you save the image in the local storage? In this case, it would be better to send the Uri of the saved file instead of the raw bitmap.

Felipe Silveira
  • 513
  • 4
  • 8
0

Passing large amounts of data by intent does not always work. Although not documented, this often fails. See

and many more.

A good work-around would be to (a) save the bitmap to a file (b) pass the filename, by intent, to the detail activity, (c) In the detail activity re-create the bitmap.

Community
  • 1
  • 1
EJK
  • 12,332
  • 3
  • 38
  • 55
  • if i understand correctly you mean to call again from web with Async the images in my Detail Activity? – gas Oct 05 '14 at 14:33
  • You don't have to do a 2nd download from the web. After the first download, you will have Bitmap which you will then save to a local file on the device. It is the path to the local file that you will send to the next activity. Then the 2nd activity will create the bitmap from the file. Thus there is no need for a 2nd web download. – EJK Oct 05 '14 at 14:39
0

The easiest way to pass complex objects that I have found is using EventBus: https://github.com/greenrobot/EventBus

Using EventBus you avoid having to serialize the data in any way, they are made directly available for other Activities/Fragments and regular classes even.

My answer to this question has some explanation on the subject: Saving information from one fragment and dialog if the user navigates to another fragment

This article also has some nice small examples of how simple it is plus some comparison to other approaches: http://www.stevenmarkford.com/passing-objects-between-android-activities/

Community
  • 1
  • 1
cYrixmorten
  • 7,110
  • 3
  • 25
  • 33
  • i am using pojo but i cant pass the bitmap i creates an wrong loop.what about eventBus?should i change my project to use it?i have no idea how it works – gas Oct 05 '14 at 15:14
  • Try and see Example 3 of the last link, it is painfully simple :) do not think you would have to change any previous code to add it to the project. – cYrixmorten Oct 05 '14 at 15:59
  • yeah i saw it.So i just import the jar file? – gas Oct 05 '14 at 17:03