-1

problem in sending image from one activity to another but able to send text to another activity, placing some source code with file name please see and correct the mistake, if possible so please writedown the required code because i am facing this problem for last two days, i have submitted this question 3 times in stackoverflow but i am not getting good answer, please someone write correct things which i need to do and write required code for me, but here i am placing some code of mine:

MainActivity Code:

 list.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
             // getting values from selected ListItem
                String title = ((TextView) view.findViewById
          (R.id.title)).getText().toString();
                String artist = ((TextView) view.findViewById
          (R.id.artist)).getText().toString();
                String duration = ((TextView) view.findViewById
          (R.id.duration)).getText().toString();
                byte[] image = null;
                Bitmap thumb_url = BitmapFactory.decodeByteArray
          (image, 0, image.length);


            //  Bitmap bMap = BitmapFactory.decodeByteArray
          (array, 0, array.length);

                // Starting new intent
                Intent in = new Intent
          (getApplicationContext(),    SingleMenuItemActivity.class);
                in.putExtra(KEY_TITLE, title);
                in.putExtra(KEY_ARTIST, artist);
                in.putExtra(KEY_DURATION, duration);
                in.putExtra(KEY_THUMB_URL, thumb_url);
                startActivity(in);

            }
        });     
    }   
    }

ReceivingActivity Code:

public class SingleMenuItemActivity  extends Activity {

// XML node keys
private static final String KEY_TITLE = "title";
private static final String KEY_ARTIST = "artist";
private static final String KEY_DURATION = "duration";
private static final String KEY_THUMB_URL = "thumb_url";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);

    // getting intent data
    Intent in = getIntent();

    // Get XML values from previous intent
    String title = in.getStringExtra(KEY_TITLE);
    String artist = in.getStringExtra(KEY_ARTIST);
    String duration = in.getStringExtra(KEY_DURATION);

    ImageView image = (ImageView)findViewById(R.id.thumb_url);
    Object thumb_url = null;
    View bitmap = null;
    bitmap.setBackgroundResource((Integer) thumb_url);   
    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);
    TextView lblCost = (TextView) findViewById(R.id.email_label);
    TextView lblDesc = (TextView) findViewById(R.id.mobile_label);

   //what code to write for image here 

    lblName.setText(title);
    lblCost.setText(artist);
    lblDesc.setText(duration);

}
 }

XML File Code:

    <ImageView     
        android:id="@+id/thumb_url"   
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/rihanna"/>


   <TextView android:id="@+id/name_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="25dip"
        android:textStyle="bold"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:textColor="#43bd00"/>

      <TextView android:id="@+id/email_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#acacac"/>

    <TextView android:id="@+id/mobile_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"/>
 </LinearLayout>
4

3 回答 3

1

我可能弄错了,但我认为您尝试通过意图传递的对象的大小有限制(失败的活页夹事务错误?)。

最好的变体是将此图像存储在某处(内存或磁盘缓存)并仅将图像链接传递给您的活动,因此它将从缓存中检索图像。即使第二个活动重新启动,您也可以轻松地将链接保存在某处(onSaveInstanceState),而无需使用原始位图进行操作。

于 2012-09-25T10:49:27.187 回答
0

尝试这个

1.

使用 Intent = new Intent (your activity.this,SingleMenuItemActivity.class);

代替

Intent in = new Intent(getApplicationContext(),SingleMenuItemActivity.class);

2.

Intent in = getIntent();

    // Get XML values from previous intent
    String title = in.getStringExtra(KEY_TITLE);
    String artist = in.getStringExtra(KEY_ARTIST);
    String duration = in.getStringExtra(KEY_DURATION);
    Bitmap bitmap =(Bitmap) in.getParcelableExtra(KEY_THUMB_URL);

    ImageView image = (ImageView)findViewById(R.id.thumb_url);


    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);
    TextView lblCost = (TextView) findViewById(R.id.email_label);
    TextView lblDesc = (TextView) findViewById(R.id.mobile_label);

    image.setImageBitmap(bitmap); 

    lblName.setText(title);
    lblCost.setText(artist);
    lblDesc.setText(duration);

}
于 2012-09-25T10:49:30.767 回答
0

Bitmap 实现 Parcelable,因此您始终可以在意图中传递它:

Intent in = new Intent
      (getApplicationContext(),    SingleMenuItemActivity.class);
            in.putExtra(KEY_TITLE, title);
            in.putExtra(KEY_ARTIST, artist);
            in.putExtra(KEY_DURATION, duration);
            in.putExtra(KEY_THUMB_URL, thumb_url);
            startActivity(in);

并在另一端检索它:

Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
image.setImageBitmap(bitmap); 
于 2012-09-25T10:50:38.957 回答