Any workaround to save an Intent in settings?

后端 未结 2 673
小蘑菇
小蘑菇 2020-12-09 19:54

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 n

相关标签:
2条回答
  • 2020-12-09 20:24

    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 讨论(0)
  • 2020-12-09 20:44

    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);
    }
    
    0 讨论(0)
提交回复
热议问题