开发者

Any workaround to save an Intent in settings?

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开发者_C百科, 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.


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


Instead of saving the Intent you could just save the String which is necessary to build the Intent.

Example:

Intent intent = new Intent("com.android.notepad.action.EDIT_TITLE");

Now you just store a String containing com.android.notepad.action.EDIT_TITLE

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜