A
A
Alexander Vasyuchenko2016-03-22 16:01:34
Android
Alexander Vasyuchenko, 2016-03-22 16:01:34

How to close PreferenceFragment programmatically?

I created a template AppCompatPreferenceActivity in android studio with PreferenceFragment headers.
It has an ActionBar with a home button. It is processed in the header like this:

@Override
        public boolean onOptionsItemSelected(MenuItem item) {
            int id = item.getItemId();
            if (id == android.R.id.home) {
                startActivity(new Intent(getActivity(), SettingsActivity.class));
                return true;
            }
            return super.onOptionsItemSelected(item);
        }

But this is not exactly what I need. I would like this header to be closed by the home button as when the Back Button is pressed in the device, i.e. so that nothing superfluous hangs in the Back Stack ...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-22
@alexv1981

call onBackPressed() on the activity instead of startActivity() for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question