-5

I want to know if there is a way to pass a class object, which can't implement serializable interface between 2 android activities. I know that to pass data using intent you have to implement serializable interface, but unfortunately I can't do this, any idea?

public class ContactMongo implements Serializable{
private DB collection;
public ContactMongo() 
{ }

}

DB doesn't implement serializable, so I can't perform intent.putExtra();

GCM 4IB
  • 21
  • 1
  • 1
  • 4

2 Answers2

0

You probably want to use a service, but you haven't told us anything about what you're trying to pass, so I guess you want to use ugly hacks.

There is such an ugly hack available, but it'll quickly get out of control (especially if you cannot even search on this topic by yourself) - you can extend your Application class and use its methods to pass data between activities. Generally, it should be avoided and other ways to pass data and let activities communicate should be used (like extracting the data from the object you want to pass).

Hope this helps you, comment if you have any questions (I'll update my answer with better solution if you give more information on what you're trying to do)

Markaos
  • 659
  • 3
  • 13
-1

You need to send an intent with whatever you want to pass.

Intent intent = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.editText);
    Object object;
    intent.putExtra("nameforyourobject", object);
    startActivity(intent);

https://developer.android.com/training/basics/firstapp/starting-activity.html

Vojb-
  • 19
  • 5
  • His class doesn't implement `Serializable` nor `Parcelable` nor is one of the supported data types for `putExtra()`. And he tells he cannot implement `Serializable` – Markaos Jun 08 '17 at 13:10