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.