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

The Archive Base Latest Questions

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

I’ve a class implementing AsyncTask. It computes an object (User) and I want to

  • 0

I’ve a class implementing AsyncTask.

It computes an object (User) and I want to return that object to main (UI) thread to be passed to a new activity.

I know it is done with Activity.runOnUiThread() but I can’t understand what to pass to this function etc? (I want to set a variable User usr = value , in main thread)

How should I do?

Thank you

EDIT:
using “Vipul Shah” code I get “unexcepted close”.
This is the log (from logcat):

06-12 10:28:05.404: E/AndroidRuntime(1475): FATAL EXCEPTION: AsyncTask #1
06-12 10:28:05.404: E/AndroidRuntime(1475): java.lang.RuntimeException: An error occured while executing doInBackground()
06-12 10:28:05.404: E/AndroidRuntime(1475):     at android.os.AsyncTask$3.done(AsyncTask.java:278)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.lang.Thread.run(Thread.java:856)
06-12 10:28:05.404: E/AndroidRuntime(1475): Caused by: java.lang.NullPointerException
06-12 10:28:05.404: E/AndroidRuntime(1475):     at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:513)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at es.es.ValidacionThread.doInBackground(ValidacionThread.java:65)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at es.es.ValidacionThread.doInBackground(ValidacionThread.java:1)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-12 10:28:05.404: E/AndroidRuntime(1475):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-12 10:28:05.404: E/AndroidRuntime(1475):     ... 4 more

ValidacionTask full source code:

package es.es;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Handler;



public class ValidacionThread extends AsyncTask<String, Object, 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";
    private AccesoCuentaActivity act;

    //Handler handler;

    private Context context;

    public ValidacionThread(Context context){
        this.context = context;
    }

    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) {
                //  JOptionPane.e.printStackTrace();
                    // 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(Usuario usu) {
          Intent intent = new Intent(context, MainActivity.class);
           intent.putExtra("result", usu);
           context.startActivity(intent);
           super.onPostExecute(usu);

        }

       protected void onProgress(Usuario usu) {

        }

}
  • 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-05T10:50:07+00:00Added an answer on June 5, 2026 at 10:50 am

    It computes an object (User) and I want to return that object to main
    (UI) threa to be passed to a new activity.

    Computation of object should happen in doInBackground method and once done use onPostExceute method to do UI Part.

    Below snippet will help you.

    Sample Activity Class.

        public class HelloActivity extends ListActivity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            new MyTask(this).execute("");
        }
    
    
    }
    

    MyTask.java

    class MyTask extends AsyncTask<String, Object, String> {
    
            private Context context;
    
            public MyTask(Context context) {
                this.context = context;
            }
    
            @Override
            protected String doInBackground(String... params) {
                // Do background operations here and once done return the result.
    
                return result;
            }
    
            @Override
            protected void onPostExecute(String result) {
    
                // Here you will receive that result.
    
                Intent intent = new Intent(context, SecondActivity.class);
                intent.putExtra("result", result);
                context.startActivity(intent);
                super.onPostExecute(result);
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.