SamSPICA SamSPICA - 10 days ago 6
Android Question

Android: Transferring strings / values within Tabs, each tab having its own activity (other than Getters-Setters)

I have a tabbed layout in my application, and want the settings part to be another tab in the UI. The settings involve entering a quantity / number of entities present (e.g.: number of balls). This data is then required to be transferred to the other tabs, which process the input data, and process the display within the respective tabs accordingly (say the number of balls= 3, then there should be 3 buttons in the 2nd tab, if balls= 1, then only 1 button, and so on...). I want to avoid the data being sent to the parent activity, and then to the respective child activities, which requires the whole app to restart [startActivity()], and individual transfer is not possible, since startActivity() for child activities would result in only the child activity contents being displayed. In which case I have to ultimately use the Getters and Setters. Is there any other / better method which I can follow in this case...?

Answer

Singletons are not the best choice for Android application because Dalvik VM may load singleton class twice and destroy all your stored data.

Also storing data in your own Application object not suitable because system may kill this object on low memory and does not restore its state on resume.

The best way, imho, is sending data via Intent object or getters/setteres, storing in at onPause method.

Comments