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 9274137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:17:04+00:00 2026-06-18T16:17:04+00:00

I am creating an app, when you log in with user name and password,

  • 0

I am creating an app, when you log in with user name and password, it requests the info from the server.
The server’s request takes time (15-20 sec), meanwhile I want to show a spinning bar with few words.
But I tried so many variations of the AsyncTask class, and I can’t get it to work. It gets the information okay, but freezes the screen until the response.
Right now I just have a new thread implementing runnable. I’m not sure from where in the code I need to call the AsyncTask .

The onClick triggers the attemptLogin() function:

    public void onClick(View view) {
        attemptLogin();
    }

In attemptLogin() function:

// more code
showProgress(true);
new Thread(new GetServerResponseRunnable()).start();
while (wait) {}
// more code

And the Runnable is:

public class GetServerResponseRunnable implements Runnable {
    @Override
    public void run() {
        response = getInfo.getTours(mUsername, mPassword);
        wait = false;   
    }       

}  

Which as you can see call another function from a different class.
This is the function:

public String getTours(String username, String password) {
    String req = "GETALLDATA";
    String retStr = "";
    try {
        url = getURL(req, username, password);
        sendOutputLine(url, "");
        retStr = getReturnString();
        Log.d(LoginActivity.DEBUG_TAG, "getTours() return: " + retStr);
    } catch (Exception e) {
        Log.d(LoginActivity.DEBUG_TAG, "programm bommed client: " + e.getMessage());
    }
    return retStr;
}   

I need help, please. Mainly what I want to do is:

    response = getInfo.getTours(mUsername, mPassword);
    wait = false;

And show the spinning bar meanwhile.

Thanks


Update: 02.13.2013

I used this code, but I got a

02-13 09:07:16.142: E/AndroidRuntime(1046): java.lang.NullPointerException

in the line:

this.dialog.setMessage(getResources().getString(R.string.login_progress_signing_in));

Any idea why?

public class LoginTask extends AsyncTask<Object, Void, String> {

    public Context context;
    public ProgressDialog dialog;


    public void BaseTask(Context context) {
        this.context = context;
        this.dialog = new ProgressDialog(context);
    }

    @Override
    protected void onPreExecute() {
        this.dialog.setMessage(getResources().getString(R.string.login_progress_signing_in));
        this.dialog.show();

    }

    @Override
    protected String doInBackground(Object... objects) {
        String name = (String) objects[0];
        String password = (String) objects[1];
        String response = getInfo.getTours(name , password );
        return response;
    }

    @Override
    protected void onPostExecute(String response) {
        if (dialog != null && dialog.isShowing())
            dialog.dismiss();

        LoginActivity.response = response; 

        // process response as you need
    }
} 
  • 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-18T16:17:05+00:00Added an answer on June 18, 2026 at 4:17 pm

    I think you need thomething like this

    public class LoginTask extends AsyncTask<Object, Void, String> {
    
        public Context context;
        public ProgressDialog dialog;
    
    
        public BaseTask(Context context) {
            this.context = context;
            this.dialog = new ProgressDialog(context);
        }
    
        @Override
        protected void onPreExecute() {
            this.dialog.setMessage(context.getResources().getString(R.string.loading));
            this.dialog.show();
    
        }
    
        @Override
        protected String doInBackground(Object... objects) {
            String name = (String) objects[0];
            String password = (String) objects[1];
            String response = getInfo.getTours(name , password );
            return response;
        }
    
        @Override
        protected void onPostExecute(String response) {
            if (dialog != null && dialog.isShowing())
                dialog.dismiss();
    
            // process response as you need
        }
    }
    

    Call this taks

    public void onClick(View view) {
        new LoginTask(YourActivity.this).execute(name, password);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an app in C# where the user enters their name and
I am creating an app that accept user info for registration but I was
I'm creating a iOS app that requires the user to log in at startup,
I'm creating an app that should list the date and time when a button
I am creating an app in which on clicking on button user can send
My app is creating a directory so that I can store log files in
I am running an automated install of webservice on server, creating user, creating site
I am creating a basic Facebook app, and when a user without permission visits
I'm creating a rails app where users log in and look at various pages.
I'm creating an sms app that handles receiving sms operation for 2 user defined

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.