Android : Automatically open a preference pop-up in an Android app

on Saturday, September 20, 2014


I have a basic Android app with a set of Preference objects that can be edited through a Settings activity. One of these preferences is a URL to a certain page that has to be filled in by the user: it is required for the app to run and using a default value is impossible.


So I want to check if this preference is filled in and if not, redirect the user to the Settings activity and automatically open the TextEdit pop-up to edit this particular preference.


So far I have this in the main activity:



protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_overview);

SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String thePreference = sharedPref.getString(SettingsActivity.KEY_THEPREFERENCE, "");
if (thePreference.equals("")) {
// The user didn't fill in the preference yet
} else {
// The user filled in the preference, we can continue normally
}
}


I know I can create an Intent to start the settings activity:



Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivity(settingsIntent);


However, how can I let the pop-up for this preference open automatically?


0 comments:

Post a Comment