1

My application has a list of clients (with only name and age displayed) and I want to be able to edit/add more info about them that is not visible in the list. So whenever I click on a client, I want to start a second activity with all the info about him.

Can I use an intent for this? Can I pass a full Object (Client) at once with an intent?

I've looked through these two topics, but I haven't found my answer yet:

How to exchange data (objects) between different Android Activities?

How do I pass data between Activities in Android application?

Thanks in advance.

Community
  • 1
  • 1
paulof91
  • 15
  • 8

3 Answers3

1

Look at this answer: How to pass an object from one activity to another on Android

//to pass :
intent.putExtra("MyClass", obj);  

// to retrieve object in second Activity
getIntent().getSerializableExtra("MyClass");
Community
  • 1
  • 1
Vingtoft
  • 13,368
  • 23
  • 86
  • 135
  • I get the "Cannot resolve method" error when I use putExtra() method. This is how I'm trying to send the intent: NewEntry client = ClientsList.get(position); Intent intent = new Intent(HomeActivity.this, ParseClient.class); intent.putExtra("MyClient", client); startActivity(intent); What am I doing wrong? – paulof91 Oct 07 '15 at 18:16
0

I would suggest you look into saving these in the SharedPreferences file. Build a singleton AppUtil class and add functionality to save data in the shared preferences there as well as being able to retrieve said data

If you have a large amount of information being stored for the clients then you should look into SQLite as database storage.

Shrey
  • 671
  • 7
  • 14
0

The more pratice way is create a class to hold every objects that you need to change between the activities. Like that:

public class MyHolderObjects {
    public static MyObjectType mObject;
}

before start the new activity (or whatever you goes to use it), instantiate (create) the object in MyHolderObjects. And use it everywhere you need :). I prefer this approach instead serialize the object.

TroniPM
  • 329
  • 3
  • 13