3

To pass data from an Activity to a Fragment, naturally, I think of using a Bundle. The problem in my case is that the Object I need to pass is a Google Cloud Endpoint message, which is neither Parcelable nor Serializable. So how might I pass the data?

For clarity, a Google Cloud Endpoint message is a POJO that is used to pass data to and from endpoint methods. I assume they would be Serializable, but to my surprise they aren't.

learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

0

You can:

  • Subclass and implement Serializable or Parcelable on that class
  • Or use any other strategy to pass data inside of the app:
    • Singleton class holding any memory cache you may use
    • If the fragment is inside of the activity you can access the fragment from the activity and pass the variable in
    • In the worst of cases you can always use SharedPreferences or any kind of disk persistence
Jose L Ugia
  • 5,960
  • 3
  • 23
  • 26