0

The Android project in question already uses Serializable to pass information between internal modules.

I am working on one of those Modules which also uses External Libraries to calculate Navigation Routes.

I need to pass one of those "external" objects to another module, this is not Serializable so I am not able to send it normally. The programmer before me had transformed all non serializable Objects in static variables in a Wrapper Class, I am not sure if that is a good idea even though the modules should remain active the whole time.

This is the Serializable wrapper class:

private static Road road;
private NavigationStep firstNavigationStep;

/**
 * To send the route information to the App. Here is everything the app needs to display the
 * data to the user.
 * @param road the route the user is to follow
 * @param firstNavigationStep the users location and the current Step.
 */
public CurrentRoad(Road road, NavigationStep firstNavigationStep){
    this.firstNavigationStep = firstNavigationStep;
    this.road     = road;
}

Writing the Road as transient makes me lose data, writing a whole wrapper class for road would be too much work(it is needed to build overlays, so a lot of Geometry is inside and is from an external library so I may forget something). Changing the whole Project to Parcelable is also not realistic.

Is there any solution? Is the best way really to just save what I need as static?

Raeglan
  • 514
  • 1
  • 5
  • 17

2 Answers2

0

Try using EventBus. Send Sticky event, containing object reference. It will be delivered to every subscribed object until you explicitly cancel that event.

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
  • There is already a message service described in our architecture, it uses Serializable. It is a MessageManger written by someone else on the project. I am kinda new in the team and the project spans through more than one company so adding an external library is not so simple – Raeglan Dec 20 '16 at 09:53
0

Perhaps you can use an event (http://greenrobot.org/eventbus/) to pass the object to where you need it.

Julius
  • 159
  • 1
  • 1
  • 13
  • There is already a message service described in our architecture, it uses Serializable. It is a MessageManger written by someone else on the project. I am kinda new in the team and the project spans through more than one company so adding an external library is not so simple – Raeglan Dec 20 '16 at 09:53
  • Ok, I'm not sure i understand the nuances of your question, but perhaps you can try to store it in an singleton instance in your (perhaps extended) application class. Assuming you always have access to the application context, that will allow you to store something that should live as long as your application. Then perhaps an intent or some other signal to trigger that the value from this singelton class should be read on the receiving end. – Julius Dec 20 '16 at 10:02