Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any workaround to save an Intent in settings?

Tags:

android

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.

like image 707
Waza_Be Avatar asked May 11 '10 16:05

Waza_Be


People also ask

How do I save intent data?

Then in your onCreate do this: @Override protected void onCreate(Bundle savedInstanceState) { super. onCreate(savedInstanceState); // Always call the superclass first // Set Content View and initialize the views // Check whether we're recreating a previously destroyed instance if (savedInstanceState !=

What is intent setType in Android?

setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.


1 Answers

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);
}
like image 183
aeracode Avatar answered Nov 15 '22 15:11

aeracode