0

On example we have an app that tracks Taxi drivers, a taxi driver log in into application and pick an order to drive for given customer.

In this case we have an Order class that represents a lot of data, it's very important to have access to this object from anywhere while still being able to modify it.

From now we can:

  • pass it by putting extra data to an intent, but it's not something that makes code readable, in some cases it won't be a solution
  • deserialize the object into json and store it into cache, we still need to constantly update this value which is a headache when more complex objects are in game, one mistake and god knows when the mismatch happens
  • store it into class that extends Application, this is approach I am testing right now, but I am having doubts about this as when app crashes / android will release app resources randomly, I am in need to restore given object state using black magic with cache anyway

This is a problem that I believe is shared across many applications, like Spotify's current playing track, etc.

Are there other approaches?

Bartłomiej Sobieszek
  • 2,692
  • 2
  • 25
  • 40

1 Answers1

0

Try using a sqlite database. In this case, you can access your data anywhere from your app if you create a robust GetOrders API method yourself.

Here is a tutorial of creating a database.

In this case, you will never lose any data if app exits or crashes. Also, it really makes no difference compared with caching your data in memory.

Fangming
  • 24,551
  • 6
  • 100
  • 90