I'm creating an AlertDialog
. Here's the snippet of code that I'm using:
final CharSequence[] items = {"Red", "Green", "Blue"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
});
AlertDialog alert = builder.create();
alert.show();
This works fine but I haven't been able to figure out how save the selection option somewhere so that the next time the alert dialog is opened, the previously selected option is shown. I don't need this value to persist across application restarts, only as long as the application is in the background and not entirely discarded.
Being new to Android development, I have found this pretty difficult to accomplish.