Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top