2013-01-01 172 views
0

我有以下方法來保存應用程序設置中的連接字符串,是否有任何處理用戶可以「讀寫」信息的Android文件(如asp.net中的web配置) ?Android設置|(文件)配置

public static System.String StrConnectionstring 
      { 
       get 
       { 
        if (DB._StrConnectionstring == null) 
        { 
         return AppSettings.GetConnectionSettings("DSN"); 
        } 
        return DB._StrConnectionstring; 
       } 
       set { DB._StrConnectionstring = value; } 
      } 
+0

http://developer.android.com/reference/android/content/SharedPreferences.html – Simon

回答

0

使用共享偏好:

聲明:

public static final String MYPREFS = "MySharedPreferenceFile"; 
SharedPreferences settings; 
SharedPreferences.Editor editor; 

初始化:

settings = context.getSharedPreferences(MYPREFS, 0); 
editor = settings.edit(); 

存儲值:

editor.putString("Name","test"); 
editor.commit(); 

要檢索值:

settings.getString("Name",""); // here value field is for to specify default value 

感謝。

+0

v gud答案...........但我需要一點解釋。 –

+0

@mak你可以參考這個鏈接的理論解釋和例子。 [http://developer.android.com/guide/topics/data/data-storage.html#pref]。謝謝。 –