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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:00:29+00:00 2026-06-05T16:00:29+00:00

I have an application which logs in into a webservice. I start a new

  • 0

I have an application which logs in into a webservice. I start a new thread when the login button is clicked and show a progress dialog while the device is communicating with the server. Based on the success or failure of the attempt I send a message to the handler of 1 – success and -1 -failure. But how do I create and start a new intent based on this message? Or how should I handle this situation otherwise. Here is my code for the Login Activity:

public class Login extends Activity implements OnClickListener {

private static final int DIALOG = 0;
private static String TAG="LoginActivity";
private ProgressDialog progressDialog;

private final Handler handler =  new Handler() {
    public void handleMessage(Message msg) {

        int state = msg.arg1;
        if (state != 0)
        {
            Log.i(TAG, "dialog dismissed, message received "+state);
            dismissDialog(DIALOG);
        }


    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    View loginButton = findViewById(R.id.login_button);
    loginButton.setOnClickListener(this);

}

public void onClick(View v) {

    switch (v.getId()) {
    case R.id.login_button:
        Log.i(TAG,"login button");
        showDialog(DIALOG);

        Intent i = new Intent(this, PTVActivity.class);
        startActivity(i);
        break;

    }
}

protected Dialog onCreateDialog(int id)
{
    switch(id) {
    case DIALOG:
        progressDialog = new ProgressDialog(Login.this);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setMessage(getString(R.string.login_progress));
        return progressDialog;
    default:
        return null;
    }
}

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch(id) {
    case DIALOG:

        EditText nameText=(EditText)findViewById(R.id.login_name);
        EditText pwText=(EditText)findViewById(R.id.password);
        String name = nameText.getText().toString();
        String pw = pwText.getText().toString();

        CommunicateServer communicate= new CommunicateServer(name,pw,handler);
        communicate.run();
    }


}

}

and here is the run() method of my CommunicateServer class:

@Override
public void run() {


    Message msg = handler.obtainMessage();
    if (login()==true)msg.arg1 = 1;
    else msg.arg1 = -1;
    handler.sendMessage(msg);

}
  • 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-05T16:00:31+00:00Added an answer on June 5, 2026 at 4:00 pm

    To create a new Intent and start an activity you have to do following:

    Intent intent = new Intent(Login.this, anotherActivity.class);
    startActivity(intent);
    

    The simplest way of handling this type of work is to use AsyncTask (example):

    In your case you have to show a Progress dialog in onPreExecute() method of AsyncTask.

    In the doInBackground(..) you will be making a server call for authentication. You have to return the status (1 or -1) from doInBackground(..) method.

    Finally you will get the status value (1 or -1) in onPostExecute(..) method as a parameter. Here you will be taking decision based on the status. If it is 1 you will be creating a new intent to open an Activity. You should also dismiss the progress dialog in this method.

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

Sidebar

Related Questions

I have an application which logs into an online site using POST form being
I have a C# application which loads at startup, and logs data to a
Hai I have developed a standalone application in which when an user logs in,
I have an application which logs changes to records in the production table to
I have a c++ application which logs to some file using log4cxx (RollingFile appender).
I have an windows application (WPF) in which we are running on each login,
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for
I have application which needs to use a dll (also written by me) which
I have an application which uses the microsoft kinect device. The thing is that
I have an application which uses code that produces various types of objects and

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.