我有一个应用程序,我可以从中启动我手机上安装的其他应用程序,长按我得到应用程序选择器,结果我收到一个 Intent 数据,我如何保存它以便用户在关闭时返回我的应用程序具有相同的快捷方式设置?
我像这样保存其他东西
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();
但我不能对 Intent 做同样的事情
最佳答案
好的,我找到了一个方法 我这样保存 Intent
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();
}
关于java - 在共享首选项中保存 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11956271/