문제

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