How to pass an custom object between applications using intent in android?

有帮助吗?

解决方案

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.

其他提示

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
}

You can use Content Provider to share data between applications... This is the link

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top