4

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?

i save other things like this

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

DoubleP90
  • 1,249
  • 1
  • 16
  • 29

2 Answers2

8

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();
    }
DoubleP90
  • 1,249
  • 1
  • 16
  • 29
0

You could serialize the object to a string, and save the resulting string in the preferences. An easy way would be to serialize it in json format, using Google Gson for example.

kgautron
  • 7,915
  • 9
  • 39
  • 60
  • I'm not familiar with gson, can you provide me an alternative? i looked on how to convert it to uri, than back to intent, but i can't find anything, i found this https://groups.google.com/forum/?fromgroups#!topic/android-developers/cffRLznyto0%5B1-25%5D But it doesn't work, i can save it, but i can't use the getIntent because it says it's deprecated – DoubleP90 Aug 14 '12 at 16:28