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

  • Home
  • SEARCH
  • 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 8274129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:38:46+00:00 2026-06-08T07:38:46+00:00

My android application has a login feature and it is accessing the users information

  • 0

My android application has a login feature and it is accessing the users information from my online server. It can also detect a registered user whether he/she has activated his/her account through email message confirmation.

But my problem is, my application almost closes when it’s retrieving users details from the database.. I have watched some videos regarding ProgressDialog and I don’t know if it can be inserted in my program properly, please help me.

Here’s my code.

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.firstscreen);

    initialise();

    bGotoRegister.setOnClickListener(new View.OnClickListener()
    {    
        public void onClick(View view)
        {
            Intent i = new Intent(getApplicationContext(), Register.class);
            startActivity(i);
        }
    });        
}

private void initialise()
{
    // TODO Auto-generated method stub
    etEmail = (EditText) findViewById(R.id.loginEmail);
    etPassword = (EditText) findViewById(R.id.loginPassword);
    bLogin = (Button) findViewById(R.id.loginSubmit);
    tvEmailError = (TextView) findViewById (R.id.loginEmailError);
    tvPasswordError = (TextView) findViewById (R.id.loginPasswordError);
    bGotoRegister = (Button) findViewById (R.id.goToRegister);

    bLogin.setOnClickListener(this);
}

public void onClick(View v) 
{
    httpclient = new DefaultHttpClient();
    httppost = new HttpPost("http://mysite.com/login.php");
    stringEmail = etEmail.getText().toString();
    stringPassword = etPassword.getText().toString();

    try 
    {
        nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("stringEmail", stringEmail));
        nameValuePairs.add(new BasicNameValuePair("stringPassword", stringPassword));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        response = httpclient.execute(httppost);
        if(response.getStatusLine().getStatusCode()== 200)
        {
            entity = response.getEntity();
            if(entity != null)
            {   
                InputStream instream = entity.getContent();
                JSONObject jsonResponse = new JSONObject(convertStreamToString(instream));

                String errorEmail = jsonResponse.getString("errorEmail");
                if (errorEmail != "")
                {
                    tvEmailError.setText(errorEmail);
                }else{}

                String errorPassword = jsonResponse.getString("errorPassword");
                if (errorPassword != "")
                {
                    tvPasswordError.setText(errorPassword);
                }else{}

                String inactiveAccount = jsonResponse.getString("inactiveAccount");
                if (inactiveAccount.length() != 0)
                {                       
                    AlertDialog alert = new AlertDialog.Builder(FirstScreen.this).create();
                    alert.setCancelable(false);
                    alert.setMessage("Your account is currently inactive and unusable." + "\nDo you want to send an account activation message to your email now?");
                    alert.setButton("Yes", new DialogInterface.OnClickListener()
                    {   
                        public void onClick(DialogInterface arg0, int arg1)
                        {
                            httpclient = new DefaultHttpClient();
                            httppost = new HttpPost("http://mysite.com/activate2.php");
                            stringEmail = etEmail.getText().toString();
                            stringPassword = etPassword.getText().toString();

                            try
                            {
                                nameValuePairs = new ArrayList<NameValuePair>();
                                nameValuePairs.add(new BasicNameValuePair("stringEmail", stringEmail));
                                nameValuePairs.add(new BasicNameValuePair("stringPassword", stringPassword));

                                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                response = httpclient.execute(httppost);
                                if(response.getStatusLine().getStatusCode()== 200)
                                {
                                    entity = response.getEntity();
                                    if(entity != null)
                                    {
                                        InputStream instream = entity.getContent();
                                        JSONObject jsonResponse = new JSONObject(convertStreamToString(instream));

                                        String successActivation = jsonResponse.getString("successActivation");
                                        if (successActivation.length() != 0)
                                        {
                                            //Progress Dialog here.
                                            Toast.makeText(getBaseContext(), "We successfully sent an activation message to your email account. Try to log in again after activating your account.", Toast.LENGTH_LONG).show();
                                        }
                                        else
                                        {
                                            Toast.makeText(getBaseContext(), "Sorry, we are unable to reach your email account.",Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }   
                            }
                            catch (Exception e)
                            {
                                e.printStackTrace();
                                Toast.makeText(getBaseContext(), "Connection to the server is lost. Please check your internet connection.", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                    alert.setButton2("Not now", new DialogInterface.OnClickListener()
                    {   
                        public void onClick(DialogInterface arg0, int arg1)
                        {
                            AlertDialog alert2 = new AlertDialog.Builder(FirstScreen.this).create();
                            alert2.setCancelable(false);
                            alert2.setMessage("Are you sure you want to exit?");
                            alert2.setButton("Yes", new DialogInterface.OnClickListener()
                            {   
                                public void onClick(DialogInterface arg0, int arg1)
                                {
                                    finish();
                                }
                            });
                            alert2.setButton2("No", new DialogInterface.OnClickListener()
                            {   
                                public void onClick(DialogInterface arg0, int arg1)
                                {
                                    //Do nothing
                                }
                            });
                            alert2.show();
                        }
                    });
                    alert.show();
                }else{}

                if ((errorEmail.length()==0) && (errorPassword.length()==0)&& (inactiveAccount.length()==0))
                {                       
                    String dbEmail = jsonResponse.getString("dbEmail");
                    String dbPassword = jsonResponse.getString("dbPassword");
                    //---Store dbEmail and dbPassword to SharedPreferences---//
                    //-------------------------------------------------------//
                    Intent i = new Intent(getApplicationContext(), Construction.class);
                    startActivity(i);
                    finish();
                }

            }//if (entity!=null)..      
        }//if response()...
    }//try..
    catch(Exception e)
    {
        e.printStackTrace();
        Toast.makeText(getBaseContext(), "Connection to the server is lost. Please check your internet connection.", Toast.LENGTH_SHORT).show();
    }   
}//END onClick()
  • 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-08T07:38:47+00:00Added an answer on June 8, 2026 at 7:38 am

    You are establishing a HTTP Connection on Main thread which is a bad way of programming in Android.

    The Web Connection is kind of a blocking call that mean your Main thread will be struck on onClick until there is a response received from the server in either success or failure.

    As the Main Thread is blocked in network connection your App becomes unresponsive to the other events such as Touch / tap or any kind of life cycle events and will not be able to update the UI as well. Which is why your application will crash / no update is displayed in the progress Dialog.

    I recommend you to use AsyncTask for any network related tasks so that your Main thread is not blocked.

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

Sidebar

Related Questions

I'm trying to write an android application that has two main activities: login screen
I have an Android application which has a login screen. Upon the click of
I had developed Android Application which has Login Authentication Page. When the user logs
I'm a new android developer and developing an application that has a login screen.
My Android application allows users to update their Facebook status from a Fragment. I've
My android application has several warnings of the following form when I run it
My Android Application has only one activity called MainActivity . When I press the
I am developing the android application in which The application has a stored password
I want to implement PDF viewer in my Android application. My application has option
In order for the user to control the volume , my android application has

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.