Starting intent after Async task gets over

后端 未结 3 1225
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 20:17

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

3条回答
  •  隐瞒了意图╮
    2021-01-26 20:53

    Add a checker to your AsyncTask such as

    // Background ASYNC Task to login by making HTTP Request 
    class LoginEmployer extends AsyncTask { 
    
    boolean validUser = false;
    

    Then once the user is validated inside your background task set the value to true

     if (Integer.parseInt(res) == 1) { 
          // user successfully logged in 
          // Store user details in SQLite Database 
    
         validUser = true;  //set valid to true
    

    Now in postExecute check if the user is valid

    protected void onPostExecute(String file_url) { 
        // dismiss the dialog once done 
        pDialog.dismiss(); 
        if ( validUser )
        {
            Intent homepage = new Intent( LoginEmployerActivity.this, 
            HomepageEmployerActivity.class); 
    
            // Close all views before launching Employer 
            // homePage 
             homepage.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
             startActivity(homepage); 
        }
    

提交回复
热议问题