eterpoir
eterpoir

Reputation: 11

How can i send object from one application to another in android

I want to send a list of object form a class that I have created through intent from one application, and get this list in one other.

I tried this :

Intent i = new Intent();

i=getActivity().getPackageManager().getLaunchIntentForPackage(getString(R.string.package_app));

ArrayList<MyClass> list = new ArrayList<MyClass>();

i.setAction(Intent.ACTION_SEND);

i.putExtra(Intent.EXTRA_TEXT, list);

i.setType("text/plain");

And to get it i have done this :

Intent receivedIntent = getIntent();

ArrayList<MyClass> getList = new ArrayList<MyClass>();

getList=(ArrayList<MyClass>)receivedIntent.getSerializableExtra(Intent.EXTRA_TEXT);

startActivity(i);

But i have an exception when i want to get the list

Upvotes: 0

Views: 304

Answers (1)

user4571931
user4571931

Reputation:

According to your stack trace you need to make the MyClass serializable.

Then you can pass the list of MyClass to second activity.

This can be as shown below:

class MyClass implements Serializable
{
//your implementation
}

In your 1st activity you need to do something like this:

Intent i = new Intent(context,secondactivity.class);

ArrayList<MyClass> list = new ArrayList<MyClass>();
i.putExtra("listdata",list);

In your 2nd activity you need to do something like this:

Intent receivedIntent = getIntent();

getList=receivedIntent.getSerializableExtra("listdata",null);

Hope this helps...

Upvotes: 1

Related Questions