How to pass an custom object between applications using intent in android?
Asked
Active
Viewed 157 times
-4
-
3Between applications or between activities? – Simon Feb 24 '14 at 12:34
-
use singleton http://stackoverflow.com/a/19763218/1012284 – Padma Kumar Feb 24 '14 at 12:39
-
Between applications. – curious_cat Feb 24 '14 at 12:39
-
@v1kas between applications use ContentProvider just like contacts provider – Raghunandan Feb 24 '14 at 12:40
3 Answers
0
Try something like below. Put below code in your main activity from where you want to pass the data.
Intent i = new Intent("com.your_app_package_name.your_app_name.ActivtiyAlpha");
i.putExtra("KEY_DATA_EXTRA_FROM_ACTV_B", myString);
// add extras to any other data you want to send to b
and in other activity.
Bundle b = getIntent().getExtras;
if(b!=null){
String myString = b.getString("KEY_DATA_EXTRA_FROM_ACTV_B");
// and any other data that the other app sent
}
InnocentKiller
- 5,207
- 7
- 34
- 84
-
3
-
thanks for the reply ,this works when i want to pass a string however in my case i want to pass a custom object that i have defined. – curious_cat Feb 24 '14 at 12:36
-
1the class must implement parcelable and then you can pass the custom object to another class – Raghunandan Feb 24 '14 at 12:38
-
but title of the question is something like what i have posted, Then also it is my mistake. – InnocentKiller Feb 24 '14 at 12:39
-
@InnocentKiller if you disagree with the question posted and it does not show enough effort you can downvote and close the question appropriately – Raghunandan Feb 24 '14 at 12:40
-
@InnocentKiller even according to the question wants to pass data between applications – Raghunandan Feb 24 '14 at 12:42
-
@Raghunandan, Yeah true only, That's why only i have posted the answer, but it's Okay it is my mistake only that i did not read carefully. – InnocentKiller Feb 24 '14 at 12:43
0
Implementing Parcelable might seems like a good fit, but it would cause issues if you ever modify your object structure. Both applications would need to be up-to-date, or the de-serialization would crash.
I would go for a JSON or XML serialization, and pass the String as an Intent extra.
nicopico
- 3,571
- 1
- 26
- 30
0
You can use Content Provider to share data between applications... This is the link
Looking Forward
- 4,200
- 8
- 46
- 66