Question

In my Android application, I've just created a User Settings activity (extending PreferenceActivity).
I want a few settings/buttons to trigger some methods from my main activity. How should I do that?

a) Make everything in my main activity static? (doesn't seem to be a good idea)

b) Send main activity as Parcelable when opening User Settings? (putExtra())

c) (another suggestion?)

Was it helpful?

Solution

I don't know specifically what you are doing, but since it's preferences I would save my preferences in SharedPreferences, and then I would make my MainActivity implement SharedPreferences.OnSharedPreferenceChangeListener and call it's methods when the right preferences were changed.

OTHER TIPS

Do the methods need to be executed immediately? Could you not use startActivityForResult(), then whenever a setting is changed which requires a method call in the main activity, set a flag or something in the result intent? Then when the preferenceActivity finishes, and returns to the main activity, you could check the returned intent and execute any necessary methods then?

Apologies if I'm talking rubbish!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top