Sunishtha Singh
Sunishtha Singh

Reputation: 321

finish activity in android closing application

i want to register on click register button then after new user is registered it goes back to login screen. for that i am using

@Override
    public void onClick(View v) {
    username = eusername.getText().toString();
    email = eemail.getText().toString();
    mobile = emobile.getText().toString();
    password = epassword.getText().toString();
    registerViews();
    if(Validations.hasNoChars(username) && Validations.isEmail(email) && Validations.isMobileNumber(mobile) && Validations.isNotEmpty(password)) 
    {            
        new CreateUser().execute();
        Toast.makeText(RegisterActivity.this, "User Registered", Toast.LENGTH_LONG).show();
        //RegisterActivity.this.finish();

    }        

   else{
       Toast.makeText(RegisterActivity.this, "Fields are empty", Toast.LENGTH_LONG).show();
   }
  finish();
}   

by this is switched to login screen but application closes. i don't know what I did wrong.

Upvotes: 0

Views: 777

Answers (3)

Ravi Makvana
Ravi Makvana

Reputation: 2912

put finish(); in AsyncTask CreateUser() of onPostExecute()

Upvotes: 1

Aakash
Aakash

Reputation: 5261

There is no need to start login activity again. You must be finishing your login activity when starting the registration activity. Don't use finish() method while starting registration activity.

Upvotes: 0

Khubab Hamza
Khubab Hamza

Reputation: 176

    if(Validations.hasNoChars(username) && Validations.isEmail(email) && Validations.isMobileNumber(mobile) && Validations.isNotEmpty(password)) 
    {            
        new CreateUser().execute();
        Toast.makeText(RegisterActivity.this, "User Registered", Toast.LENGTH_LONG).show();
       Intent it=new Intent(this,login.class);
startActivity(it);

    } 

Try to do this is your Async executes successfully it will transfer you to login activity.

Upvotes: 1

Related Questions