android-activitysharearcorecustom-objectsceneform

Share ARCore Renderable between Activities


How do I share a Sceneform Renderable between activities?

I have an app where the user can read information about an object which has probably a renderable linked. In activity A, if a renderable is linked a click on a button starts an ARCore activity B to view and interact with the renderable.

I load the renderable before asynchronously from a database in activity A for two reasons. First, to have it in memory and second, to know if there is a renderable to show.

Right now, Serializable Parcelable are not implemented by Sceneform Renderable and due to its complexity I cannot create an own class capable of doing that.

My try would be to make an static class where I store the renderable in memory on activity A, startActivity B, and then readout the Sceneform Renderable in activity B and remove the entry from the static store class. But the question is, are there better more efficient ways to share a Sceneform Renderable, or any other custom complex object, between activities?

I want do avoid waiting times in activity B where the renderable should be instantly available because the user must be able to view it due to he is coming form activity A.


Solution

  • Using a singelton class with static put and get methods to access a private hashmap does the trick.

    In the put method, the unserializable, unparcelable references have to be put into the hashmap with a key, in my case, the id from the database. Then the unserializable, unparcelable references inside object you want to share between activities must be set to null.

    When the other activity has started and your object to share has arrived use its key to retrive the unserializable, unparcelable references from he hash map and (re)set their references as fields in object you wanted to share.

    Now one can share custom objects with unserializable, unparcelable fields between activities.