在共享偏好中保存意图

Dou*_*P90 2 java android

我有一个应用程序,我可以启动我的手机上安装的其他应用程序,长按我得到应用程序选择器,结果我收到一个意图数据,我如何保存它,以便用户关闭时回到我的应用程序有相同的快捷方式设置?

我保存这样的其他东西

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();
Run Code Online (Sandbox Code Playgroud)

但我无法对意图做同样的事情

Dou*_*P90 5

好吧,我找到了一种方法,我保存这样的意图

SharedPreferences settings = getSharedPreferences(PREFERENCES, 0);
                SharedPreferences.Editor editor = settings.edit();
                String uriString = data.toUri(requestCode); 
                editor.putString("Contacts_app", uriString);
                editor.commit();
Run Code Online (Sandbox Code Playgroud)

然后我像这样检索它

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();
    }
Run Code Online (Sandbox Code Playgroud)