简体   繁体   中英

onActivityResult in Activity not called after startActivityForResult from Fragment in API 18

I want the user to select a picture from his gallery, therefore I have the following.

I have a SettingsActivity where it says:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        //do sth here
    }
}

In the onCreateMethod of this SettingsActivity i do:

getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();

And then I have the SettingsFragment which does the following in the onCreate()

Preference pref = (Preference) findPreference(SettingsConstants.Key.PREF_BACKGROUND_IMAGE);
    pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
            intent.putExtra(Intent.CATEGORY_OPENABLE, true);
            intent.setAction(Intent.ACTION_GET_CONTENT);
            getActivity().startActivityForResult(Intent.createChooser(intent, "Select Picture"), SettingsActivity.RESULT_LOAD_IMAGE);
            return true;
        }
    });

This worked in 4.2 - but is not working with 4.3 anymore! Can anyone tell me what I'm missing here, or is anyone facing the same issue?

它被调用,但是您在片段中设置的请求代码在onActivityResult活动的方法的参数中有所不同!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM