In our project we are forbidden to store data from server (confidentional information). But once downloaded and parsed models are used in multiple fragments. Data on server updates once a day and forced logout occurs in midnight. I want to store parced models in memory and remove it at exit from app.
In current implementation I have two single-instance classes - RestClient and DataStorage, which in constructors are registered to Otto bus. I instance them in Application class:
@Override
public void onCreate() {
super.onCreate();
new RestClient(this);
new DataStorage();
}
DataStorage for every model have metods:
@Subscribe
public void onModelComplete(Model model) {
this.model = model;
}
@Produce
public Model produceModel() {
return model;
}
Fragments send events throw bus to RestClient and receive results from RestClient or "produced" results from DataStorage (if data is received while app in background).
The problem is that when the user exits the application, data is not deleted because the application does not die. How to implement storing in memory with clearing data on exit without killing process?