Search code examples
androidviewpreferencesshared

Share a value across all views of my activity


This question is more like a discussion about how you guys would do it.

I'm developing an application that has an Avatar Creation, but this creating occurs across two different Activities.

In the first one the user selects whether is man or a woman and a name, in the next Activity the user has to select his face, hair, clothes and etc.

Since the views for hair and etc changes if the user is a man or a woman how would you implement a way to pass the gender value to all the Views?

I was thinking about using a static member to hold the value so I could access inside my views, or maybe I should use SharedPreferences to do it.

I think using the SharedPreferences is a more elegant way to do it but I'm wondering if there isn't any other better and more elegant way of doing it.

Has anyone thought about other implementations?


Solution

  • If its only a small information like "gender" i don't see much harm using "Static" variable(Ofcourse the static variable will become null if your app crashes when its in the background).

    SharedPreference will come good if you want the information to be persistent(But i don't see you need this).

    One more choice is you do can extend the application class to store the static data across activities.