java - Unable to pass array of objects via intent extras -
i'm passing arraylist of movie objects mainactivity
detailactivity
via intent.
intent.putextra(key_mfavoritemovies, mfavoritemovies); startactivity(intent);
in other activity, i'm adding additional movie objects.
mfavoritemovies(movie);
however, mfavoritemovies
in mainactivity
not appear contain additional movie objects.
is behavior expected?
that expected behaviour because when modify array list @ detailactivity
working different instance of movies list.
you can changes make list starting detailactivity
startactivityforresult
, sending updated list mainactivity
you have @ mainactivity
arraylist<string> mmovies; int detail_request_code = 123; string key_favorite_movies = "key-movies"; private void startdetailactivity() { intent intent = new intent(this, detailactivity.class); intent.putstringarraylistextra(key_favorite_movies, mmovies); startactivityforresult(intent, detail_request_code); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == detail_request_code && resultcode == result_ok) { mmovies = data.getstringarraylistextra(key_favorite_movies); } }
and have send updated list detailactivity
this:
public void finishdetail() { intent resultintent = new intent(); resultintent.putstringarraylistextra(key_favorite_movies, mmovies); setresult(activity.result_ok, resultintent); finish(); }
Comments
Post a Comment