How to return from preference screen to main activity?

依然范特西╮ 提交于 2019-12-05 09:57:30

On my first activity I call menu and go on preferenceActivity by calling startActivityForResult.

Using startActivityForResult() with a PreferenceActivity is rather unusual. PreferenceActivity is designed to be used with startActivity(). If the one starting the PreferenceActivity cares about preference changes, it should register a preference change listener with the SharedPreferences object.

Then I change my settings and want to return on main activity and see main activity with new settings applyed.

I recommend that you use a SharedPreferences.OnSharedPreferenceChangeListener instead. Or, simply re-read the preferences you care about in the original activity's onStart() or onResume() method.

In onPause() method do following (as I right understand this method will be called when I press back button, right?)

No, that will not work. onPause() is too late to call setResult().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!