1
所以基本上,我的服务显示一个通知,如果用户希望可以关闭。Android服务getSharedPreferences问题
设置从应用程序内部进行控制,并通过PreferenceActivity进行设置。
当退出活动:
public void onDestroy(){
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
debug.postLog(Log.DEBUG, "Settings", "("+this.toString()+") showNotification: " + prefs.getBoolean("showNotification", true));
显示正确的值,如果用户取消选中的复选框,它显示了假,反之亦然。
同时,当我把这个在我服务的任何时间:
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Boolean show = prefs.getBoolean("showNotification", true);
debug.postLog(Log.DEBUG, "Passive Service", "("+this.toString()+") showNotification: " + prefs.getBoolean("showNotification", true));
if(prefs.getBoolean("showNotification", true)){
我得到相同的结果,直到应用程序完全停止后再重新启动,则当前值保持。这几乎就像服务获得了偏好的快照。
我错过了什么?
我有完全相同的问题。我很担心这个。我只需要删除'android:process =“:remote”' –