I have a bit of usual problem here. I have a alertdialog that launches as soon as my application has been launched and as soon as the user clicks the ok button that dialog will never display again unless it has been deleted and installed again. It works when I try it on my emulator for the first time and by first time I mean when I launch the application as soon I am done writing the code for the shared preference for the alertdialog. But when I close the emulator and launch my application again, the alertdialog doesn't display and my application doesn't respond to anything. I do not know if this happened to anybody before and I do not know if this was suppose to happen. Can somebody help me understand what is going and why application doesn't respond to anything after the first time the application has been launched. Also my logcat did not display any errors either.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SharedPreferences settings = getSharedPreferences("pref_name", 0);
boolean installed = settings.getBoolean("installed", false);
if(!installed){
final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setTitle("Title");
alertDialog.setIcon(R.drawable.ic_launcher);
alertDialog.setAdapter(new MyAdapter(), null);
alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("installed", true);
editor.commit();
}
});
alertDialog.show();
final EditText et = (EditText) findViewById(R.id.editText1);
Button getAnswer = (Button) findViewById(R.id.button1);
getAnswer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (et.getText().toString().length()==0) {
Toast.makeText(getApplicationContext(),"Can't Be Blank!",Toast.LENGTH_LONG).show();
}else{
EditText et = (EditText) findViewById(R.id.editText1);
String searchTerm = et.getText().toString().trim();
Intent in = new Intent(MainActivity.this, ListView.class);
in.putExtra("TAG_SEARCH", searchTerm);
startActivity(in);
}
}
});
}
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}}