[英]Save intent in shared preference
我有一個應用程序,從中可以啟動手機上安裝的其他應用程序,長按一次即可得到應用程序選擇器,結果我收到了意圖數據,如何保存它,以便用戶在關閉時返回到我的應用程序具有相同的快捷方式設置?
我保存這樣的其他東西
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("Counter1", counter);
editor.putBoolean("FirstRun", firstRun);
editor.putString("Label2", label2S);
editor.commit();
但是我無法做到這一點
好吧,我找到了一種保存這樣的意圖的方法
SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
SharedPreferences.Editor editor = settings.edit();
String uriString = data.toUri(requestCode);
editor.putString("Contacts_app", uriString);
editor.commit();
然后我像這樣檢索它
SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
String contactsApp = settings.getString("Contacts_app", null);
try {
telApp = Intent.parseUri(contactsApp, 0);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
您可以將對象序列化為字符串,然后將結果字符串保存在首選項中。 一種簡單的方法是將其序列化為json格式,例如使用Google Gson 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.