Alert dialog closes without pressing the button and Activity goes to home page
<p>I'm building an android app with a Login activity. If email is not valid, I want to show an alertbox with a "Email not valid" message and want to stay at same  activity. The problem is that the alertbox is shown only for a brief time and then I go back immediately to the parent activity, without pressing any button in the alertbox. my code is:</p>

<pre><code>if (v.getId() == R.id.loginButton) {

         if(checkEmail(emailtheGame.toString())==true)
         {
             startActivity(new Intent(this, BackgroundImages.class));
         }
         else
         {
             email=emailtheGame.toString();
             showDialog(0);               
     }

        finish();
boolean checkEmail(String inputMail) {   
        Pattern pattern= Pattern.compile("^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\\.([a-zA-Z])+([a-zA-Z])+");
        return pattern.matcher(inputMail).matches();
    }

@Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case 0:
            return new AlertDialog.Builder(this)
                    .setTitle("Showing Response.........")
                    .setMessage("sdfdsfdfsdf")
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                        int whichButton) {
                                    Toast.makeText(getBaseContext(),
                                            "OK clicked!", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            })

                    .create();  
    }
        return null;
    }
</code></pre>

<p>Any help is highly appreciated......!!!</p>
