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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:14:38+00:00 2026-06-09T18:14:38+00:00

I have a login page that accepts username & password. When the user clicks

  • 0

I have a login page that accepts username & password. When the user clicks “Login” a loading screen “Signing in..” is shown with the background thread calling a doLogin() method that calls a web service and load the appropriate page.

The problem I am facing is to “Cancel” signing in from Dialog.cancel() after login has been clicked. It cancels the loading screen but the background thread is still processing and even after clicking “cancel”, the new page is loaded. How can I cancel the background thread?

Thread backgroundWorker = new Thread(new Runnable() {
    public void run() {
        doLogin(uname, pwd);
    }
});
Dialog busyDialog = new Dialog("Signing in...",
                               new String [] { "Cancel" },
                               new int [] { Dialog.CANCEL},
                               Dialog.CANCEL,
                               Bitmap.getPredefinedBitmap(Bitmap.HOURGLASS))
{
    public void fieldChanged(Field field1, int context1)
    {
        //Something to stop the login and close the loading screen
    }
};
busyDialog.setEscapeEnabled(false);
busyDialog.show();
backgroundWorker.start();

And the method which it is calling that pushes the new screen is doLogin():

private String doLogin(String user_id, String password)
{
    SoapObject resultRequestSOAP = null;
    HttpConnection httpConn = null;
    HttpTransport httpt;
    SoapPrimitive response = null;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("username", user_id);
    request.addProperty("password", password);
    System.out.println("The request is=======" + request.toString());
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    httpt = new HttpTransport(URL+C0NNECTION_EXTENSION);
    httpt.debug = true;
    try
    {
        httpt.call(SOAP_ACTION, envelope);
        response = (SoapPrimitive) envelope.getResponse();
        String result = response.toString();
        resultRequestSOAP = (SoapObject) envelope.bodyIn;
        String[] listResult = split(result, sep);
        strResult = listResult[0].toString();
        if(strResult.equals("credentialdenied"))
        {
            Dialog.alert("Invalid login details.");
        }
        else
        {
            strsessionFirstName = listResult[1].toString();
            strsessionLastName = listResult[2].toString();
            strsessionPictureUrl = MAINURL + listResult[3].substring(2);
            strsessionStatusId = listResult[4].toString();
            strsessionStatusMessage = listResult[5].toString();
            strsessionLastUpdateTst = listResult[6].toString();
        }
        if(strResult.equals("credentialaccepted"))
        {
            if(checkBox1.getChecked() == true)
            {
                persistentHashtable.put("username", user_id);
                persistentHashtable.put("password", password);
            }
            Bitmap bitmap = getLiveImage(strsessionPictureUrl, 140, 140);
            nextScreen.getUsername(user_id);
            nextScreen.getPassword(password);
            nextScreen.setPictureUrl(bitmap);
            nextScreen.setImage(strsessionPictureUrl);
            nextScreen.setFirstName(strsessionFirstName, strsessionLastName, strsessionLastUpdateTst, strsessionStatusMessage);
            UiApplication.getUiApplication().invokeLater( new Runnable()
            {
                public void run ()
                {
                    UiApplication.getUiApplication().pushScreen(nextScreen);
                }
            } );
        }
    } catch (IOException e) {
        System.out.println("The exception is IO==" + e.getMessage());
    } catch (XmlPullParserException e) {
        System.out.println("The exception xml parser example==="
           + e.getMessage());
    }
    System.out.println( resultRequestSOAP);
    return response + "";
} 
  • 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-09T18:14:40+00:00Added an answer on June 9, 2026 at 6:14 pm

    You might need to add a boolean member variable to your class, that you check at multiple steps, within your doLogin() method:

    private boolean stopRequested = false;
    
    private synchronized void requestStop() {
        stopRequested = true;
    }
    
    private synchronized boolean isStopRequested() {
        return stopRequested;
    }
    
    private String doLogin(String user_id, String password)          
    {          
        SoapObject resultRequestSOAP = null;          
        HttpConnection httpConn = null;          
        HttpTransport httpt;          
        SoapPrimitive response = null;          
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);          
        request.addProperty("username", user_id);          
        request.addProperty("password", password);          
        System.out.println("The request is=======" + request.toString());          
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);          
        envelope.dotNet = true;          
        envelope.setOutputSoapObject(request);          
        httpt = new HttpTransport(URL+C0NNECTION_EXTENSION);          
        httpt.debug = true;
    
        if (isStopRequested()) return null;          
    
        try          
        {          
            httpt.call(SOAP_ACTION, envelope);          
            response = (SoapPrimitive) envelope.getResponse();          
            String result = response.toString();          
            resultRequestSOAP = (SoapObject) envelope.bodyIn;          
            String[] listResult = split(result, sep);          
            strResult = listResult[0].toString();          
            if(strResult.equals("credentialdenied"))          
            {          
                Dialog.alert("Invalid login details.");          
            }          
            else          
            {          
                strsessionFirstName = listResult[1].toString();          
                strsessionLastName = listResult[2].toString();          
                strsessionPictureUrl = MAINURL + listResult[3].substring(2);          
                strsessionStatusId = listResult[4].toString();          
                strsessionStatusMessage = listResult[5].toString();          
                strsessionLastUpdateTst = listResult[6].toString();          
            }    
    
            if (isStopRequested()) return null;          
    
            if(strResult.equals("credentialaccepted"))          
            {          
                if(checkBox1.getChecked() == true)          
                {          
                    persistentHashtable.put("username", user_id);          
                    persistentHashtable.put("password", password);          
                }          
                Bitmap bitmap = getLiveImage(strsessionPictureUrl, 140, 140);          
                nextScreen.getUsername(user_id);          
                nextScreen.getPassword(password);          
                nextScreen.setPictureUrl(bitmap);          
                nextScreen.setImage(strsessionPictureUrl);          
                nextScreen.setFirstName(strsessionFirstName, strsessionLastName, strsessionLastUpdateTst, strsessionStatusMessage);
    
                if (isStopRequested()) return null;          
    
                UiApplication.getUiApplication().invokeLater( new Runnable()          
                {          
                    public void run ()          
                    {          
                        UiApplication.getUiApplication().pushScreen(nextScreen);          
                    }          
                } );          
            }          
        } catch (IOException e) {          
            System.out.println("The exception is IO==" + e.getMessage());          
        } catch (XmlPullParserException e) {          
            System.out.println("The exception xml parser example==="          
               + e.getMessage());          
        }          
        System.out.println( resultRequestSOAP);          
        return response + "";          
    }           
    

    Then, stop the thread like this:

    Dialog busyDialog = new Dialog("Signing in...",               
                                   new String [] { "Cancel" },               
                                   new int [] { Dialog.CANCEL},               
                                   Dialog.CANCEL,               
                                   Bitmap.getPredefinedBitmap(Bitmap.HOURGLASS))               
    {               
        public void fieldChanged(Field field1, int context1)               
        {               
            requestStop();               
        }               
    };  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Login page that captures User input like this. MD5calc ss =
So, I have set up a login page that verifies the user's credentials, and
I have made a web application that uses master page for Login & Logout
So, I have a simple login page that has a light green background, and
I'm using ASP.NET MVC 2 and have a login page that is secured via
I have code that redirects visitor to login -page via authentication provider selector -page
I have written a django page that requires only super users to login. So
I have a TextView that displays an error message in the login page of
I have an Employee class object that I am calling from my Login.aspx page's
I have a login page that I would like to show in https. After

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.