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

The Archive Base Latest Questions

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

I’ve an android application. I need to execute a code on a separate task

  • 0

I’ve an android application.

I need to execute a code on a separate task because it fives me android.os.NetworkOnMainThreadException .

This is my code:

 public class AccesoCuentaActivity extends Activity{
   public void validacion(View v) throws IOException, XmlPullParserException
{
    try {
    String usuario=((EditText)findViewById(R.id.etUsu)).getText().toString();
    String pass=((EditText)findViewById(R.id.etPass)).getText().toString();
    String[] pars = new String[2];

             String[] = new String[2];
             pars[0] = usuario;
    pars[1] = pass;
            new ValidacionThread().execute(pars);
             Intent intent=new Intent(this, MainActivity.class);
    intent.putExtra("idBoton",12);
    intent.putExtra("usuario",usu);
    startActivityForResult(intent, 0);          

} }

Task:

public class ValidacionThread extends AsyncTask<String, Void, Usuario> {

    private final String NAMESPACE = "http://webservices.pcp/";
    private final String URL = "http://127.0.0.1:8080/webServices/pcpWS?wsdl";
    private final String SOAPACTION = "";
    private final String METHOD = "ValidarUsuario";

    protected Usuario doInBackground(String[] pars) {

               String user = pars[0];
               String password = pars[1];
                SoapObject request = new SoapObject(NAMESPACE, METHOD); 
                SoapSerializationEnvelope sobre = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                sobre.dotNet = false;       
                request.addProperty("login", user);        
                request.addProperty("password", password); 
                sobre.setOutputSoapObject(request); 

                HttpTransportSE transporte = new HttpTransportSE(URL);        
                try {
                    transporte.call(SOAPACTION, sobre);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                SoapObject resultado = null;
                try {
                    resultado = (SoapObject)sobre.getResponse();
                } catch (SoapFault e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                Usuario usu = new Usuario();
                usu.IdUsuario= resultado.getProperty(0).toString();
                usu.Nombre = resultado.getProperty(1).toString();
                usu.Apellidos = resultado.getProperty(2).toString();
                usu.Rol = resultado.getProperty(3).toString();   
                usu.Centro=resultado.getProperty(4).toString();
                return usu;     

}
       protected void  onPostExecute(ValidacionThread vt) {

        }
}

It gives me two problems:

1) In class AccesoCuentaActivity :

I want to save the variable “usuario” return in ValidationThread.doInBackground(). But how do I do it?

Indeed if I just write: new ValidacionThread().execute(pars); it tells me that the variable “usu” (intent.putExtra(“usuario”,usu);) has not been initialized

while with code (in main code) Usuario usu = new ValidacionThread().execute(pars); it says type mismatch

2) In doInBackground() line eclipse gives the warning:
Varargs methods should only override or be overridden by other varargs methods unlike ValidacionThread.doInBackground(String[]) and AsyncTask<String,Void,Usuario>.doInBackground(String...)

  • 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:07:20+00:00Added an answer on June 5, 2026 at 4:07 pm

    Since this is Async task you need to create a return way for that data.
    I would recomend creating an interface like:

    interface{
    public void parseData(Usuario data);
    }

    and implementing it in your activity class.

    I would then pass and instance of activity to that async task in constructor.

    Then in your ValidationThread:

    protected void onPostExecute(Usuario vt) {
    activityInstance.parseData(vt);
    }

    As for the second part change String[] to String..

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I need to clean up various Word 'smart' characters in user input, including but

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.