Вопрос

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