0

I'm creating an app where I need to pass relatively complex classes between several Activitys and Services. Lets say something like this:

public class A implements Serializable{

    int myInt;
    String myString;
    B myB;
}

public class B implements Serializable{
    ArrayList<String> myStrings;
}

Now this can be done by Intent.putExtra(String, Serializable), but I could also create a singleton class holding the A instance. Using a singleton provides easy access to my instance of A, but it seems a bit 'hacky' to me.

What are the up and down sides of using both methods? Are there any strict reasons why I shouldn't use one of the methods?

nhaarman
  • 98,571
  • 55
  • 246
  • 278

1 Answers1

1

you could try this share data between activities.

You could use intents, Singletons class, A public static field/method, A HashMap of WeakReferences to Objects, Application Preferences, Files, contentProviders, SQLite DB.

Look here Android FAQ

Community
  • 1
  • 1
Roger Garzon Nieto
  • 6,554
  • 2
  • 28
  • 24