2012-09-22 52 views
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)){ 

我得到相同的結果,直到應用程序完全停止後再重新啓動,則當前值保持。這幾乎就像服務獲得了偏好的快照。

我錯過了什麼?

回答

1

解決了,該服務是作爲遠程運行的。

+0

我有完全相同的問題。我很擔心這個。我只需要刪除'android:process =「:remote」' –