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
You need to move this code
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);
}
}
});
}
out of the if
part of your code. As Shobhit is saying, this is never getting run the next time you run your app. It only runs if installed
is false
which is never true after the first run.
Edit-Avoid window leak errors with the Dialog
You can always check if the Dialog
is open with dialog.isShowing()
and close the Dialog if returns true before the Activity is destroyed or something (another Activity
) comes on top. You can do this in onPause().
@Override
public void onPause()
{
if (dialog != null && dialog.isShowing())
{
dialog.dismiss();
super.onPause();
}
}