2

I have one class Days

public class Days implements Serializable {
    private String id;
    private List<Hours> hours;
    //getters and setters
}

And a class Hours

public class Hours implements Serializable{
    private String id;
    private String comments;
    //getters and setters
}

I also have an activity with a ExpandableList that shows days as groups and hours as children. When I click on a specific hour, I pass the object hours to edit on another activity.

public class DaysListActivity extends ExpandableListActivity
            implements OnChildClickListener
{
    //Other methods
    @Override
    public boolean onChildClick(parameters...)
    {
        Intent i = new Intent(getApplicationContext(),HourActivity.class);
        i.putExtra("hourClicked",day.getHour(idHourClicked));
        startActivity(i);
    }
}

In HourActivity.class

public class HourActivity extends Activity{
    @Override
    public void onCreate(Bundle savedInstance)
    {
        ...
        Intent i = getIntent();
        Hour hour = (Hour) i.getSerializableExtra("hourClicked");
        updateHour(hour);
        ....
    }

    public void updateHour(Hour hour)
    {
        hour.setComment("Hellow world");
        Toast toast = Toast.makeText(getApplicationContext(), hour.getComment(), Toast.LENGHT_SHORT);
        toast.show();
    }    

}

Everything goes fine, the toast shows me "Hello world". But when i came back to DayListActivity, the hour that i've clicked and updated keeps the same value, it doesn't refresh. Wrost, if I click on the same hour again, i'ts like it was never updated to "Hello world"

I've already tried notifyDataSetChanged() on adapter and invalidateViews() on ExpandableListView. Which step am I missing?

Heitor Colangelo
  • 494
  • 9
  • 16

1 Answers1

2

It's another object. You've serialized the object, treat the new one in another activity and came back.

Open the child activity with startActivityForResult and, in there, serialize the resulting object before return.

In the onActivityResult, deserialize it again. You're done.

You've got tons of resources on this respect How do I pass data between Activities in Android application?

Btw... I'd do a master-detail thing, so to child activity i'd only send the id of the record and reload the data when i'm back.

Community
  • 1
  • 1
eduyayo
  • 2,020
  • 2
  • 15
  • 35
  • Sorry, i forgot to mention that this app could not have a database. I'm working with objects in memory. I'll try this and back later to give a feedback. By now, thank you for the answer! – Heitor Colangelo Sep 25 '14 at 21:11
  • Mh... Then store the things in the Application context. So u can uae the same references from one activity and the other. – eduyayo Sep 25 '14 at 21:14
  • 1
    Works! with startActivityForResult, then a replace the object that came back from Hours --> Days. Thank you! – Heitor Colangelo Sep 25 '14 at 21:51