1

I'm new on Android and I want to know how I can use Serializable in my code

First Activity:

@Override
public void onItemClick(Neighbour item) {
    Intent i = new Intent(getActivity(), ProfilNeighbourActivity.class);
    i.putExtra("avatar", item.getAvatarUrl());
    i.putExtra("name", item.getName());
    i.putExtra("city", item.getAddress());
    i.putExtra("phone", item.getPhoneNumber());
    i.putExtra("about", item.getAboutMe());
    i.putExtra("fbUrl", item.getFbUrl());
    startActivity(i);
}

Second Activity:

    mAvatar = findViewById(R.id.profil_neighbour_image);
    mName1 = findViewById(R.id.profil_neighbour_name1);
    mName2 = findViewById(R.id.profil_neighbour_name2);
    mCity = findViewById(R.id.profil_neighbour_city);
    mPhone = findViewById(R.id.profil_neighbour_phone);
    mAbout = findViewById(R.id.profil_neighbour_about);
    mFbUrl = findViewById(R.id.profil_neighbour_fbUrl);

    Intent i = getIntent();
    String image = i.getStringExtra("avatar");
    String name = i.getStringExtra("name");
    String city = i.getStringExtra("city");
    String phone = i.getStringExtra("phone");
    String about = i.getStringExtra("about");
    String fbUrl = i.getStringExtra("fbUrl");
    Glide.with(this).asBitmap().load(image).fitCenter().into(mAvatar);
    mName1.setText(name);
    mName2.setText(name);
    mCity.setText(city);
    mPhone.setText(phone);
    mFbUrl.setText(fbUrl + name);
    mAbout.setText(about);

How can I shorten my code with Serializable please?

Ariakah
  • 31
  • 6
  • Does this answer your question? [How to send an object from one Android Activity to another using Intents?](https://stackoverflow.com/questions/2139134/how-to-send-an-object-from-one-android-activity-to-another-using-intents) – Nitish Jan 05 '22 at 11:05

1 Answers1

1

you can use passing objects around then Parcelable

more details : Parcelable

Pouria Hemi
  • 706
  • 5
  • 15
  • 30