保存意向共享preference [英] Save intent in shared preference

查看:145
本文介绍了保存意向共享preference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我可以启动安装在我的手机上的其他应用程序,具有悠久点击我得到的应用程序选择器的应用,结果我收到意图数据,我怎么能保存它,以便用户在关闭一个回来我的应用程序具有相同的快捷键设置?

I have an application from which i can launch other apps installed on my phone, with a long click i get the app picker, in result i receive an intent data, how can i save it so the user when closes an comes back to my app has the same shortcuts setup?

我救其他的东西像这样

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();

但我不能做同样的意图

But i can't do the same with the intent

推荐答案

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

Ok i found a way I save the intent like this

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

然后我检索它像这样

Then i retrieve it like this

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();
    }

这篇关于保存意向共享preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆