Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9157555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:02:52+00:00 2026-06-17T13:02:52+00:00

I am developing an app which requires a user to login.The login is working

  • 0

I am developing an app which requires a user to login.The login is working ok through a url.
However when i add an AsyncTask to add a progress dialog,the app does not change intent.I have tried every possible method i know in vain.
below is the code:

  package com.epolicing;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener{
    Button loginButton;
    EditText usernme,passwrd;
    TextView error;
    String username,password;
    static final int Dialog_logging_in=1;
    boolean userverified=false;

    // Session Manager Class
     SessionManager session;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login); 
        session = new SessionManager(getApplicationContext()); 
        loginButton = (Button) findViewById(R.id.loginButton);
        usernme = (EditText) findViewById(R.id.UserName);
        passwrd=(EditText) findViewById(R.id.password);
        username=usernme.getText().toString().trim();
        password=passwrd.getText().toString().trim();
        error=(TextView)findViewById(R.id.errorTextView);
        loginButton.setOnClickListener(this);
    }

     protected Dialog onCreateDialog(int id){
      Dialog dialog = null;
      switch(id){
      case Dialog_logging_in:
          ProgressDialog.show(LoginActivity.this,"","Authenticating user...");
          break;
          default:
              dialog=null;
      }
      return dialog;

     }


    public void onClick(View v) {
        switch(v.getId()){
        case R.id.loginButton:
            String user,pass;
            user=usernme.getText().toString();
            pass=passwrd.getText().toString();

            if(user.equals("")||pass.equals("")){       
                message();
            }
            else {
                new log_in().execute(this);
            }
            break;
            }

        }

    //login method
      public void login() {
                ArrayList<NameValuePair>postParameters=new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("username",usernme.getText().toString()));
                postParameters.add(new BasicNameValuePair("password",passwrd.getText().toString().trim()));

                //String valid="1";
                String response=null;
                try{
                    response=CustomHttpClient.executeHttpPost("http://10.0.2.2/epolicing/tologin.php",postParameters);
                    String res=response.toString();
                    res=res.replaceAll("\\s+","");
                    if(res.equals("0")) {
                 error.setText("Wrong password or username combination");
                    }
                    else {
                        String usern=usernme.getText().toString().trim();
                        session.createLoginSession(usern,res);
                        userverified=true;
                        //Intent intent=new Intent(LoginActivity.this,menu.class);
                        //startActivity(intent);    
                    }
                }
                catch(Exception e){
                    error.setText(e.toString());

                }

      }


      public void message(){
        Context context=getApplicationContext();
        CharSequence text="username and/or password cannot be blank";
        int duration=Toast.LENGTH_LONG;
        Toast toast=Toast.makeText(context, text, duration);
        toast.show();
    }

     private class log_in extends AsyncTask<LoginActivity,Void,LoginActivity>{
        @Override
         protected void onPreExecute(){
            showDialog(Dialog_logging_in); 
         }
        @Override
        protected LoginActivity doInBackground(LoginActivity... Params) {
            login();
            return null;
        }
        protected void onPostExecute(LoginActivity params){
            super.onPostExecute(params);
            //dismissDialog(Dialog_logging_in);
            if(userverified==true){
                Intent intent=new Intent(LoginActivity.this,menu.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                LoginActivity.this.startActivity(intent);
            }

        }


     }
}

Here is the log:

01-20 19:36:53.685: E/WindowManager(1191): Activity com.epolicing.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40555c68 that was originally added here
01-20 19:36:53.685: E/WindowManager(1191): android.view.WindowLeaked: Activity com.epolicing.LoginActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40555c68 that was originally added here
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.ViewRoot.<init>(ViewRoot.java:258)
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.Dialog.show(Dialog.java:241)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.ProgressDialog.show(ProgressDialog.java:107)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.ProgressDialog.show(ProgressDialog.java:85)
01-20 19:36:53.685: E/WindowManager(1191):  at com.epolicing.LoginActivity.onCreateDialog(LoginActivity.java:50)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.Activity.onCreateDialog(Activity.java:2482)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.Activity.createDialog(Activity.java:882)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.Activity.showDialog(Activity.java:2557)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.Activity.showDialog(Activity.java:2524)
01-20 19:36:53.685: E/WindowManager(1191):  at com.epolicing.LoginActivity$log_in.onPreExecute(LoginActivity.java:120)
01-20 19:36:53.685: E/WindowManager(1191):  at android.os.AsyncTask.execute(AsyncTask.java:391)
01-20 19:36:53.685: E/WindowManager(1191):  at com.epolicing.LoginActivity.onClick(LoginActivity.java:71)
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.View.performClick(View.java:2485)
01-20 19:36:53.685: E/WindowManager(1191):  at android.view.View$PerformClick.run(View.java:9080)
01-20 19:36:53.685: E/WindowManager(1191):  at android.os.Handler.handleCallback(Handler.java:587)
01-20 19:36:53.685: E/WindowManager(1191):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-20 19:36:53.685: E/WindowManager(1191):  at android.os.Looper.loop(Looper.java:123)
01-20 19:36:53.685: E/WindowManager(1191):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-20 19:36:53.685: E/WindowManager(1191):  at java.lang.reflect.Method.invokeNative(Native Method)
01-20 19:36:53.685: E/WindowManager(1191):  at java.lang.reflect.Method.invoke(Method.java:507)
01-20 19:36:53.685: E/WindowManager(1191):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-20 19:36:53.685: E/WindowManager(1191):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-20 19:36:53.685: E/WindowManager(1191):  at dalvik.system.NativeStart.main(Native Method)

Help will be highly appreciated.Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:02:53+00:00Added an answer on June 17, 2026 at 1:02 pm

    no need to return current Activity instance from doInBackground because AsyncTask is inner class of Activity so you just use LoginActivity.this to start next Activity change your AsyncTask class as :

       private class log_in extends AsyncTask<String,Void,String>{
            ProgressDialog pDialog;
            @Override
             protected void onPreExecute(){
                pDialog = new ProgressDialog(LoginActivity.this);
                pDialog.setMessage("Authenticating user...");
                pDialog.show();
             }
            @Override
            protected String doInBackground(String... params) {
                login();
                return null;
            }
            protected void onPostExecute(String params){
                super.onPostExecute(params);
                pDialog.dismiss();
                if(userverified==true){
                    Intent intent=new Intent(LoginActivity.this,menu.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    LoginActivity.this.startActivity(intent);
                }
               else{
                   error.setText("Wrong password or username combination");
                }
    
            }
    
         }
    

    because it’s not possible to updating UI elements from doInBackground and you are trying to set textview text inside login() method instead of changing Textview text just make userverified==false

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing android application which requires user to Login. This application relies on
I'am developing an app which requires drawing the user signature. On click of a
I am developing an app which requires the phone to ring or make some
I'm developing an app which requires the system to get the touch events even
I'm currently developing a spotify app which requires oAuth to sign into GetGlue. It
I have been developing an app in VB.NET which requires a control object (for
I am developing an app which requires interaction with a SOAP web service, to
I am developing an iPhone app which requires charts. Hence I am using API
I am developing an android app which requires search functionality. My app contains action
I am developing an app which requires a SQL DB on the device. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.