1

I need to show a preferences screen from my application. I've managed to implement this and it works on Ice-Cream Sandwich and newer devices but doesn't work on older devices like Gingebread and Froyo. I'm using ActionBarSherlock as a compatibility library to support older devices.

Here's the code for the Activity that contains the preference screen:

public class Settings extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);    
        getFragmentManager().beginTransaction()
                .replace(android.R.id.content, new Preferences())
                .commit();
    }

}

This is the sample code from my activity that invokes the preferences screen:

public class Trend extends SherlockActivity {

    @Override
    public boolean onOptionsItemSelected(MenuItem itmMenuitem) {
        if (itmMenuitem.getItemId() == R.id.search) {
            startActivity(new Intent(getBaseContext(), Settings.class));
            return true;
        }
    }

}

When users try and open the preferences screen on older devices, I get an exception that reads:

java.lang.NoSuchMethodError: com.mridang.stupidapp.Settings.getFragmentManager
at com.mridang.stupidapp.Settings.onCreate(Settings.java:15)

How should I modify my preferences screen to work with older devices i.e. API 8? Thanks.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
  • I've made a library for this here: https://github.com/AndroidDeveloperLB/MaterialPreferenceLibrary . Also, I'm not sure, but I think that Google allows something too: https://plus.google.com/+AndroidDevelopers/posts/9kZ3SsXdT2T – android developer Sep 03 '15 at 22:54

1 Answers1

2

Neither ActionBarSherlock nor the Android Support Library provides support for Preference Fragments.

You need to revert to Perference Activities as explained in the Settings Documentation.

There are a few old questions that discuss the same topic:

Community
  • 1
  • 1
Codo
  • 75,595
  • 17
  • 168
  • 206