android - How to pass a just created object from one activity to another? -
my app contains 2 activitys. activity 1 created starting app. in 1 create object of own class myclass. class contains 1 string , 3 integers. in activity object gets written. second activity b needs read object. how can pass b? or there other solution?
there couple of way can pass object 1 activity another:
1. application class: class visible application activities can save object in class 1 activity , access other.
2. can break apart class simple variables: string , 3 integers , pass them via bundle or intent self 1 activity another, construct object again.
intent intent = new intent (this, targetactivity.class); intent.putextra(key, value); intent.putextra(key, "value"); startactivity(intent);
3. if object implements serializable/parcelable can pass via bundle.
example on how serialize object:
Comments
Post a Comment