android java run activity without restarting it
<p>I created simple application which would login to DB and get data from it. But now I found a problem: If you in the first time write wrong login data and try to login second time it won't work. You have to restart it. </p>

<p>I think there is a problem in this code: <strong>EDITED</strong></p>

<pre><code>public class MyMoodleApplicationActivity extends Activity {
/** Called when the activity is first created. */
EditText username;
EditText password;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    username = (EditText)findViewById(R.id.username);
    password = (EditText)findViewById(R.id.password);
    final Button loginButton = (Button)findViewById(R.id.login);      
    loginButton.setOnClickListener(loginListener);
    final Button clearButton = (Button)findViewById(R.id.clear);
    clearButton.setOnClickListener(clearListener);
}
private OnClickListener loginListener = new OnClickListener(){

    public void onClick(View v){
        String usr = username.getText().toString();
        String psw = password.getText().toString();
        System.out.println("Username: "+usr);
        System.out.println("Password: "+psw);
        ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
        nameValuePairs.add(new BasicNameValuePair("usern",""+usr));
        nameValuePairs.add(new BasicNameValuePair("passw",""+psw));
        InputStream is = null; 
        String result = "";
        //http post
        try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://ik.su.lt/*****");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
        }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
        }
        //convert response to string
        try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
                }
                is.close();

                result=sb.toString();
        }catch(Exception e){
                Log.e("log_tag", "Error converting result "+e.toString());
        }
        String usernameFromDB = "";
        String firstnameFromDB = "";
        String lastnameFromDB = "";
        String emailFromDB = "";
        String phoneFromDB = "";
        String skypeFromDB = "";
        String cityFromDB = "";
        String descriptionFromDB = "";
        try{
                JSONArray jArray = new JSONArray(result);
                for(int i=0;i&lt;jArray.length();i++){
                        JSONObject json_data = jArray.getJSONObject(i);
                        usernameFromDB = json_data.getString("username");
                        firstnameFromDB = json_data.getString("firstname");
                        lastnameFromDB = json_data.getString("lastname");
                        emailFromDB = json_data.getString("email");
                        phoneFromDB = json_data.getString("phone1");
                        skypeFromDB = json_data.getString("skype");
                        cityFromDB = json_data.getString("city");
                        descriptionFromDB = json_data.getString("description");

                        System.out.println(usernameFromDB+ "  " + firstnameFromDB+"  "+lastnameFromDB+"  "
                                + emailFromDB + "  " + phoneFromDB +"  " + skypeFromDB+ "  " + cityFromDB + "  "+
                                descriptionFromDB);
                }
        }
        catch(JSONException e){
            AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
            alertDialog.setTitle("Klaida!");
            alertDialog.setMessage("Toks vartotojas neegzistuoja");
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    return;
                }
            });
            alertDialog.show();
                Log.e("log_tag", "Error parsing data "+e.toString());
        }
        if(usr.length()== 0){
            AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
            alertDialog.setTitle("Klaida!");
            alertDialog.setMessage("Jūs neįvedėte slapyvardžio");
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    return;
                }
            });
            alertDialog.show();
        }
        else if(psw.length()==0){
            AlertDialog alertDialog = new AlertDialog.Builder(MyMoodleApplicationActivity.this).create();
            alertDialog.setTitle("Klaida!");
            alertDialog.setMessage("Jūs neįvedėte slaptažodžio");
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    return;
                }
            });
            alertDialog.show();
        }
        else if (usr.equals(usernameFromDB)){
            Intent in = new Intent(getApplicationContext(), LoggedUser.class);
            in.putExtra("firstname", firstnameFromDB);
            in.putExtra("lastname", lastnameFromDB);
            in.putExtra("email", emailFromDB);
            in.putExtra("phone1", phoneFromDB);
            in.putExtra("skype", skypeFromDB);
            in.putExtra("city", cityFromDB);
            in.putExtra("description", descriptionFromDB);

            startActivity(in);
            finish();
    }
}};

private OnClickListener clearListener = new OnClickListener(){
    @Override
    public void onClick(View v){
        username.setText("");
        password.setText("");
    }
};
</code></pre>

<p>In these if statements I check if username and password you enter is empty username  is not equal to the one in database.
How to rewrite the code that it would work?</p>

<p><strong>Edited:</strong>
I have user john in DB but if I write John in login field and press login button it won't say that there is not the John user. And in LogCat I see that json stream is readed. Is there a way to set up a rule that upercase and lowercase letters would be different?</p>
