Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在共享首选项中保存意图_Java_Android - Fatal编程技术网

Java 在共享首选项中保存意图

Java 在共享首选项中保存意图,java,android,Java,Android,我有一个应用程序,我可以从中启动手机上安装的其他应用程序,只要长时间单击,我就会获得应用程序选择器,结果我收到一个意图数据,我如何保存它,以便用户在关闭应用程序时返回我的应用程序时具有相同的快捷方式设置 我保存其他类似的东西 SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putInt("C

我有一个应用程序,我可以从中启动手机上安装的其他应用程序,只要长时间单击,我就会获得应用程序选择器,结果我收到一个意图数据,我如何保存它,以便用户在关闭应用程序时返回我的应用程序时具有相同的快捷方式设置

我保存其他类似的东西

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);
    String contactsApp = settings.getString("Contacts_app", null);
    try {
        telApp = Intent.parseUri(contactsApp, 0);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但是我不能对意图执行相同的操作

您可以将对象序列化为字符串,并将结果字符串保存在首选项中。一个简单的方法是以json格式序列化它,例如使用。

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

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(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);
    String contactsApp = settings.getString("Contacts_app", null);
    try {
        telApp = Intent.parseUri(contactsApp, 0);
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

我不熟悉gson,你能给我一个替代方案吗?我研究了如何将它转换为uri,而不是返回到intent,但我找不到任何东西,我找到了这个但它不起作用,我可以保存它,但我不能使用getIntent,因为它说不推荐保存
(int-resultcode,intent数据)
首选的数据对象?您得到问题的答案了吗?如果有,请帮助我