任何解决方法,以保存设置的意图是什么? [英] Any workaround to save an Intent in settings?

查看:98
本文介绍了任何解决方法,以保存设置的意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望您能理解我的问题与我的英语基础...

Hope you will understand my question with my basic english...

在我的应用程序,我允许用户有一个按钮,启动了他选择的应用程序。我没有得到任何问题,使所有已安装应用程序的列表,让意图并启动已选定的应用程序。

In my application, I allow the user to have a button that launch the application of his choice. I get no problem to make a list of all installed apps, get the Intent and launch the choosen app.

不过,我想保存相应的意图,在下次用户使用我的应用程序的设置,但设置只允许我保存基本数据类型(整数,布尔,字符串等)

But I would like to save the corresponding intent in the settings for the next time the user use my application, but settings only allow me to save basic data type ( Integer, boolean, Strings, etc. )

所以,我的问题是如何保存的意图在一个聪明的办法。

So, my question is how to save an intent in a smart way.

我希望你能帮助我找到一个解决方案。

I hope you can help me to find a solution.

推荐答案

您应该使用 myIntent.toURI()存储意图,并使用 Intent.getIntent(字符串URI)恢复意图

You should use myIntent.toURI() to store the Intent, and use Intent.getIntent(String uri) to restore the Intent.

public void saveIntent(Intent intent) {
    mSharedPrefs.edit().putString(SOME_KEY, intent.toURI()).commit();
}

public Intent restoreIntent() {
    String uri = mSharedPrefs.getString(SOME_KEY, *mSomeDefaultUri*);
    return Intent.getIntent(uri);
}

这篇关于任何解决方法,以保存设置的意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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