@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_ACTION: if (resultCode == RESULT_OK) { ActionInfo.Record record = (ActionInfo.Record) data.getSerializableExtra(ActionPickerActivity.EXTRA_ACTION_RECORD); MyApp.logD("picked intent: " + record.intentUri); // save Preference pref = findPreference(mPrefKey); pref.getSharedPreferences() .edit() .putString(mPrefKey, record.toStringForPreference()) .apply(); updateActionSummary(pref, record); } break; default: super.onActivityResult(requestCode, resultCode, data); } }
protected void pickAction(@StringRes int id) { openActivityForResult( id, ActionPickerActivity.class, REQUEST_ACTION, new ExtraPutter() { @Override public void putExtras(Preference preference, Intent activityIntent) { mPrefKey = preference.getKey(); ActionPickerActivity.putExtras(activityIntent, preference.getTitle(), true); } }); Preference pref = findPreference(id); ActionInfo.Record record = ActionInfo.Record.fromPreference( pref.getSharedPreferences().getString(pref.getKey(), "")); updateActionSummary(pref, record); }
private ActionInfo.Record getActionRecord(SharedPreferences prefs, String key) { return ActionInfo.Record.fromPreference(prefs.getString(key, "")); }