0
我有偏愛活動從用戶獲取URL我面臨的問題是,當我關閉應用程序,然後再次運行應用程序時,URL狀態不會保留。我想要的是,用戶設置URL 1時間和每次應用程序使用該URL運行,直到用戶不改變它爲止。偏好活動不保留狀態
我喜歡的活動XML。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="0dp" android:layout_width="0dp">
<PreferenceCategory android:title="Authentication">
</PreferenceCategory>
<PreferenceCategory android:title="Server URL">
<EditTextPreference android:key="rootUrl"
android:title="Server URL"
android:summary="URL to upload and download data"
>
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>
優先級:
public class AppSettings extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.app_settings);
}
}
代碼我在哪裏獲得根URL的值
SharedPreferences settings= PreferenceManager.getDefaultSharedPreferences(this);
String s=settings.getString("rootUrl","default");
s=s+"?path=./";
m_urlString=s;
m_root=s;
答案是否適合您? – allprog