0

Official documentation and all examples I have seen so far suggest to explicitly write class fields in Parcel object in writeToParcel method and then read them back in constructor which takes Parcel object as an argument.

Just experimenting I left writeToParcel and a constructor empty, and still it worked. I could add this object to a Bundle object, rotate screen and then get back an instance of my class.

So can I just leave writeToParcel and a constructor empty and won't it lead to anything undesirable?

  • Put a breakpoint or `Log` statements in `writeToParcel()`. Repeat your test. Was the method called? If not, then what good was your test? – CommonsWare May 10 '14 at 19:10
  • I've just tried it. This method was not called – user3624038 May 10 '14 at 19:17
  • 2
    That means your test is flawed. Just because you put something into a `Bundle` does not mean that it goes through the process of being put into or out of a `Parcel`. In your case, the `savedInstanceState` `Bundle` (which I am guessing is what you used) is not converted into a `Parcel` for a simple configuration change. Instead, toggle on "Don't keep activities" in Developer Options in Settings. Then, run your activity and press HOME. Then, try to get back into your activity via the recent-tasks list. That should more fully exercise your code. Or, use your `Parcelable` in an `Intent` extra. – CommonsWare May 10 '14 at 19:24

0 Answers0