質問

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?)

役に立ちましたか?

解決

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.

他のヒント

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!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top