I created a login activity for my Android app. After the user enters the correct credentials, the login activity will switch over to the homepage but I don\'t know why my code w
You are calling the intent to start a new activity inside the doInBackgorund() which runs on a non-UI thread and the Activity needs to be run on a UI thread. That is why your Login activity is never stopped.
Put the code to go to the new activity inside onPostExecute() or onProgressUpdate().
Here is something you can do.
Declare a global variable loginVerfied = false;
When your doInBackground verifies that the authenticity of the user, make loginVerified = true , otherwise keep it false.
Then inside onPostExecute()
if(loginVerifed == true)
{
Intent homepage = new Intent(getApplicationContext(),HomepageEmployerActivity.class
homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(homepage);
finish();
}
EDIT :
Also, you have declared class LoginEmployer extends AsyncTask, so to call it you need to use new LoginEmployer.execute(""); (you are missing the double quotes and not passing any String to the Task so it does not match it's parameters).
The first parameter in the definition of the AsyncTask is the datatype of the value being passed to it when execute() function is called. The second parameter is the datatype related to displaying progress during the time when the background thread runs. And the third parameter specifies the return value of the result.
More about AsyncTask here.
So, here is what you need to do now.
Declare the Async Task like this.
class LoginEmployer extends AsyncTask and make a call to it by using new LoginEmployer.execute(""). Make sure to return null from your doInBackground().
Hope this solves your problem now!