Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

android - 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, 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...