1

In every example I saw, the data is somehow synonymous to basic (raw) data -- ints, chars, array of bools, and so on -- this is too limiting for me, because I would like to pass a regular object.

So how to pass any data to activity, like for example, instance of MyClass?

I checked the Intent.putExtra -- all I found was basic types + Bundle, but Bundle itself also handles only basic types.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
greenoldman
  • 16,895
  • 26
  • 119
  • 185

2 Answers2

2

There are several way to do it as described in android guide faq.

I think that in your case static variables could help most.

You could also implement Application and use it to share your data between Activities. Here is short tutorial on that.

Igor B.
  • 1,134
  • 9
  • 6
  • Thank you. However it is almost humorous how badly Android is designed, static here, static there. I have to unlearn good habits I already have :-D. – greenoldman Oct 14 '12 at 09:35
  • :) Well, yes, if you consider static variables bad, than Application is the way to go, although android framework engineer Diane Hackbosrn claims "If you are recommending Application, you are recommending use of singletons.". You can whole discussion here: http://stackoverflow.com/questions/3826905/singletons-vs-application-context-in-android – Igor B. Oct 14 '12 at 09:54
1

In every example I saw, the data is somehow synonymous to POJO data -- this is too limiting for me, because I would like to pass a regular object (not int, or string, or array of bools).

POJO = Plain Ol' Java Object = "regular object (not int, or string, or array of bools)".

So how to pass any data to activity, like for example, instance of MyClass?

Make it Parcelable.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491