0

I am trying to pass a custom object along 3 fragments. I implemented the Parcelable Interface to the class of the object and can retrieve it from the database etc. However, I noticed, whenever I pause the app, eg open another application on my phone. I get this error

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.vreeni.firebaseauthentiction, PID: 26107
              java.lang.RuntimeException: Parcel: unable to marshal value 
              com.google.firebase.firestore.FirebaseFirestore@6955b14
              at android.os.Parcel.writeValue(Parcel.java:1716)
              at com.example.vreeni.firebaseauthentication.Workout.writeToParcel(Workout.java:135)
                  at android.os.Parcel.writeParcelable(Parcel.java:1735)
                  at android.os.Parcel.writeValue(Parcel.java:1641)
                  at android.os.Parcel.writeArrayMapInternal(Parcel.java:782)
                  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)
                  at android.os.Bundle.writeToParcel(Bundle.java:1181)
                  at android.os.Parcel.writeBundle(Parcel.java:822)
                  at android.support.v4.app.FragmentState.writeToParcel(FragmentState.java:120)
                  at android.os.Parcel.writeTypedArray(Parcel.java:1406)
                  at android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:617)
                  at android.os.Parcel.writeParcelable(Parcel.java:1735)
                  at android.os.Parcel.writeValue(Parcel.java:1641)
                  at android.os.Parcel.writeArrayMapInternal(Parcel.java:782)
                  at android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1506)
                  at android.os.Bundle.writeToParcel(Bundle.java:1181)
                  at android.app.IActivityManager$Stub$Proxy.activityStopped(IActivityManager.java:4617)
                  at android.app.ActivityThread$StopInfo.run(ActivityThread.java:4003)
                  at android.os.Handler.handleCallback(Handler.java:789)
                  at android.os.Handler.dispatchMessage(Handler.java:98)
                  at android.os.Looper.loop(Looper.java:251)
                  at android.app.ActivityThread.main(ActivityThread.java:6563)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

So I resolved it by assigning the object to a variable in the fragment and then removing it and then setting it again to pass to the next fragment.

When the fragment is created:

       workout = bundle.getParcelable("Workout");
       bundle.remove("Workout");

When clicking the button to get to the next fragment:

       bundle.putParcelable("Workout", workout);
            fragment.setArguments(bundle);
            getActivity().getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, fragment)
                    .addToBackStack(null)
                    .commit();

But there must be a nicer way to do so, I was hoping!

Thanks for the help :)

Vr33ni
  • 101
  • 16
  • What you are doing is not solving the problem but dodging it :) Seems like there's some issue when marshaling `Workout` class object. Please upload that class too so we know what's causing the issue., together with a pointer on line 135 as mentioned in stack (**Workout.java:135**) – waqaslam Feb 04 '18 at 14:10
  • Thanks for the tip, I did have another look at my workout class and the error was there. I had added the firestore collection reference in the pareable fields and that caused the error. Working now :) – Vr33ni Feb 04 '18 at 16:40

0 Answers0