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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:17:29+00:00 2026-06-15T20:17:29+00:00

Hi All I want to pass a Variables to AsyncTask I’ve This Variables private

  • 0

Hi All I want to pass a Variables to AsyncTask

I’ve This Variables

private static String NAMESPACE = "aaa";
private static String METHOD_NAME = "bbb";
private static String SOAP_ACTION =  NAMESPACE + METHOD_NAME ;
private static String URL = "ccc";

and I’ve This Task

    public class Login extends AsyncTask<Void, Void, String>
    {
    ProgressDialog progress;
String response = "";
    private ProgressDialog pDialog;
public void onPreExecute() 
  {
    super.onPreExecute();
    pDialog = new ProgressDialog(MainActivity.this);
    pDialog.setMessage("Please Wait");
    pDialog.setIndeterminate(false);
    pDialog.setCancelable(false);
    pDialog.show();
  }
    @Override
protected String doInBackground(Void... arg0)       {
         final SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);             
         request.addProperty("username", user_name);
         request.addProperty("userpass", user_pass);
         final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
         envelope.setOutputSoapObject(request);
         envelope.dotNet = true;
         try 
            {
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                    androidHttpTransport.call(SOAP_ACTION, envelope);                    
                    SoapPrimitive result = (SoapPrimitive) envelope.getResponse();          
                    response = result.toString();
            }
         catch (IOException e) 
            {
             response = "Error In The Operation(1) !!\n Check Internet Connection And TRY AGAIN.";
            }
         catch (Exception e) 
            {
             response = "Error In The Operation(2) !!\n Check Internet Connection And TRY AGAIN.";
            } 
    return response;
    }
@Override
public void onPostExecute(String res)
{
            if(!(res.equalsIgnoreCase("")))
            {
                     if (res.toString().contains(",") == true)
                     {
                   String[] separated = res.split(",");
                   tv.setText(separated[1]);
                   return;
                     }

                 if(res.toString().equals("1"))
                 {
                     res = "Wrong User name OR password ,, TRY AGAIN ..";
                     tv.setText(res);
                     pDialog.dismiss();
                     return;
                 }
                 if(res.toString().equals("2"))
                 {
                     res = "Your Account Is temporarily Blocked ,, Please Call The Admin";
                     tv.setText(res);
                     pDialog.dismiss();
                     return;
                 }
                 if(res.toString().equals("3"))
                 {
                     res = "Error While Retrieve S Information ,, Try Again Later .";
                     tv.setText(res);
                     pDialog.dismiss();
                     return;
                 } 
                tv.setText(res);
                pDialog.dismiss();
            }
}
    }

I Need When I Want To Execute this Taks

To Call It And Pass The Above Variables

Like

new Login().execute();

Make It

new Login().execute(URL,NAMESPACE,METHOD,USERNAME,USERPASS);

With Knolledge That this task return a String 🙂

AND THE doInBackground MUST HAVE a value for user_name & user_pass Need To Pass It With Execution Call ..

Regards …

  • 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-15T20:17:30+00:00Added an answer on June 15, 2026 at 8:17 pm

    Why not create a Constructor for the Login class, like below? In my case, I’m passing an Activity to my AsyncTask so that I can call a callback function when done, but in your case, you could also pass an Array of your Strings.

    In this case below, the args array is passed to the class constructor while the params array is passed to the doInBackground function. The MainActivity is passed to the AsyncTask so that the taskDone callback can be called in MainActivity once the task completes.

    public class Login extends AsyncTask<String, Void, String>
    {
        private MainActivity activity;
    
        //These private strings are only needed if you require them
        //outside of the doInBackground function.... 
        //If not, just use the params argument of doInBackground by itself
        private String METHODNAME,
        private String NAMESPACE;
        private String SOAPACTION;
        private String USER_NAME;
        private String USER_PASS;
    
        public Login(String[] args, MainActivity activity) {
            this.NAMESPACE= args[0];
            this.METHODNAME = args[1];
            this.SOAPACTION = args[2];
            this.USER_NAME = args[3];
            this.USER_PASS= args[4];
    
            this.activity = activity;
        }
        @Override
        protected Void doInBackground(String... params) {
            //Again, use either params local to this function
            //or args local to the entire function... 
            //both would be redundant
            String _NAMESPACE = params[0];
            String _METHODNAME = params[1];
            String _SOAPACTION = params[2];
            String _USER_NAME = params[3];
            String _USER_PASS= params[4];
    
            //Do background stuff
        }
    
        protected void onPostExecute() {
            //dismiss progress dialog if needed
            //Callback function in MainActivity to indicate task is done
            activity.taskDone("some string");
        }
    }
    

    MainActivity.java

    private String[] args= {"mynamespace", "mymethods", "mysoap", "myuser", "mypass"}; //to pass to constructor
    private String[] params= {"mynamespace", "mymethods", "mysoap", "myuser", "mypass"}; //to pass to doInBackground
    
    //Pass your args array and the current activity to the AsyncTask
    new Login(args, MainActivity.this).execute(params);
    
    //Callback for AsyncTask to call when its completed
    public void taskDone(String returnVal) {
        //Do stuff once data has been loaded
        returnText = returnVal;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me insane. All I want to do is pass a command
All i want is to pass a HTML (DOM object) from javascript to Actionscript.
I want to pass through configuration arguments to a class. These are all the
I have a NameValueCollection with parameter. I want to pass all parameter in SqlCommand
I want to know how to pass variables from a form to a php
I wanna want to pass or share data(values) from login frame to all frames
I want to pass the name of a function testMath as a string into
I'm having all kinds of problems with getting my form to properly pass variables
All I want to do is return the index of the i that is
All I want to do is write hello world to a QGraphicsScene in a

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.