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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:36:26+00:00 2026-06-12T09:36:26+00:00

Here is my code. I am calling Asynctask inside send button and calling sendtoserver

  • 0

Here is my code. I am calling Asynctask inside send button and calling sendtoserver method which is implementing Webservice code inside doInBackground Method.

     package asynctask.com;

     import org.ksoap2.SoapEnvelope;
     import org.ksoap2.serialization.SoapObject;
     import org.ksoap2.serialization.SoapSerializationEnvelope;
     import org.ksoap2.transport.HttpTransportSE;



     import android.os.AsyncTask;
     import android.os.Bundle;
     import android.app.Activity;
     import android.app.ProgressDialog;
     import android.util.Log;
     import android.view.Menu;
     import android.view.MenuItem;
     import android.view.View;
     import android.view.Window;
     import android.view.WindowManager;
     import android.view.View.OnClickListener;
     import android.widget.Button;
     import android.widget.DatePicker;
     import android.widget.EditText;
     import android.widget.Spinner;
     import android.widget.Toast;
     import android.support.v4.app.NavUtils;

        public class Asyntask extends Activity {
         boolean resultofmail;
    Button send;
    private static final String SOAP_ACTION = "http://sendmail.com/insertfeedback";
        private static final String METHOD_NAME = "insertfeedback";
        private static final String NAMESPACE = "http://sendmail.com/";
        private static final String URL = "http://180.179.48.27:8080/sendmail      /sendmailService?wsdl";


       EditText ename;
       EditText eid,reason;
       DatePicker sdate,edate;
       Spinner rfl;




         @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.leaverequest);
        send=(Button)findViewById(R.id.button1);

        eid=(EditText)findViewById(R.id.editText1);
        ename=(EditText)findViewById(R.id.editText2);

        sdate=(DatePicker)findViewById(R.id.datePicker1);
        edate=(DatePicker)findViewById(R.id.datePicker2);
        rfl=(Spinner)findViewById(R.id.spinner1);
        reason=(EditText)findViewById(R.id.editText3);



        send.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                new MailSendingTask().execute((Void[])null);


            }
        });



         }

        public boolean sendtoserver()
          {
        int day  =sdate.getDayOfMonth();
        int month=sdate.getMonth()+1;
        int year =sdate.getYear();
        String stdate=day+"/"+month+"/"+year;

        int day1  =edate.getDayOfMonth();
        int month1=edate.getMonth()+1;
        int year1 =edate.getYear();
        String eddate=day1+"/"+month1+"/"+year1;

                Toast.makeText(getApplicationContext(),stdate+"   "+eddate,Toast.LENGTH_LONG).show();



            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
                request.addProperty("name",ename.getText().toString());
                request.addProperty("code",eid.getText().toString());
                request.addProperty("date1",stdate);
                request.addProperty("date2",eddate);
                request.addProperty("leave",rfl.getSelectedItem().toString());
                request.addProperty("reason",reason.getText().toString());



                SoapSerializationEnvelope envelope = new   SoapSerializationEnvelope(SoapEnvelope.VER11); 
                envelope.setOutputSoapObject(request);
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);


                 try {
                   androidHttpTransport.call(SOAP_ACTION, envelope);
                   Toast.makeText(getApplicationContext(),"Mail Sent",Toast.LENGTH_LONG).show();
                   return true;

                 }
                 catch (Exception e) {
                     Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
                     return false;

                    }
   }



    public class MailSendingTask extends AsyncTask <Void, Void, Void> {

        private ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            this.progressDialog = ProgressDialog.show(
                    Asyntask.this,
                    "Doing Processing", // title
                    "Sending Data To Server", // message
                    true // indeterminate
            );
        }

        @Override
        protected Void doInBackground(Void... params) {

            resultofmail=sendtoserver();
            return null;
        }

        @Override
        protected void onPostExecute(Void v) {
            this.progressDialog.cancel();
            if (resultofmail)
            Toast.makeText(getApplicationContext(), "Mail sent", Toast.LENGTH_LONG).show(); 
            else
                Toast.makeText(getApplicationContext(), "Retry", Toast.LENGTH_LONG).show(); 

        }

       }

        }

LOGCAT

10-03 00:23:38.600: E/AndroidRuntime(1770): FATAL EXCEPTION: AsyncTask #1
10-03 00:23:38.600: E/AndroidRuntime(1770): java.lang.RuntimeException: An error occured while executing doInBackground()
10-03 00:23:38.600: E/AndroidRuntime(1770):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.lang.Thread.run(Thread.java:1019)
10-03 00:23:38.600: E/AndroidRuntime(1770): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-03 00:23:38.600: E/AndroidRuntime(1770):     at android.os.Handler.<init>(Handler.java:121)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at android.widget.Toast.<init>(Toast.java:68)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at android.widget.Toast.makeText(Toast.java:231)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at asynctask.com.Asyntask.sendtoserver(Asyntask.java:89)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at asynctask.com.Asyntask$ReverseGeocodeLookupTask.doInBackground(Asyntask.java:140)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at asynctask.com.Asyntask$ReverseGeocodeLookupTask.doInBackground(Asyntask.java:1)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
10-03 00:23:38.600: E/AndroidRuntime(1770):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
10-03 00:23:38.600: E/AndroidRuntime(1770):     ... 4 more
10-03 00:23:38.770: W/IInputConnectionWrapper(1770): showStatusIcon on inactive InputConnection
10-03 00:23:39.250: E/WindowManager(1770): Activity asynctask.com.Asyntask has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40565b30 that was originally added here
10-03 00:23:39.250: E/WindowManager(1770): android.view.WindowLeaked: Activity asynctask.com.Asyntask has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40565b30 that was originally added here
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.ViewRoot.<init>(ViewRoot.java:259)
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
10-03 00:23:39.250: E/WindowManager(1770):  at android.app.Dialog.show(Dialog.java:241)
10-03 00:23:39.250: E/WindowManager(1770):  at android.app.ProgressDialog.show(ProgressDialog.java:107)
10-03 00:23:39.250: E/WindowManager(1770):  at android.app.ProgressDialog.show(ProgressDialog.java:90)
10-03 00:23:39.250: E/WindowManager(1770):  at asynctask.com.Asyntask$ReverseGeocodeLookupTask.onPreExecute(Asyntask.java:129)
10-03 00:23:39.250: E/WindowManager(1770):  at android.os.AsyncTask.execute(AsyncTask.java:391)
10-03 00:23:39.250: E/WindowManager(1770):  at asynctask.com.Asyntask$1.onClick(Asyntask.java:67)
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.View.performClick(View.java:2485)
10-03 00:23:39.250: E/WindowManager(1770):  at android.view.View$PerformClick.run(View.java:9080)
10-03 00:23:39.250: E/WindowManager(1770):  at android.os.Handler.handleCallback(Handler.java:587)
10-03 00:23:39.250: E/WindowManager(1770):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-03 00:23:39.250: E/WindowManager(1770):  at android.os.Looper.loop(Looper.java:123)
10-03 00:23:39.250: E/WindowManager(1770):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-03 00:23:39.250: E/WindowManager(1770):  at java.lang.reflect.Method.invokeNative(Native Method)
10-03 00:23:39.250: E/WindowManager(1770):  at java.lang.reflect.Method.invoke(Method.java:507)
10-03 00:23:39.250: E/WindowManager(1770):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
10-03 00:23:39.250: E/WindowManager(1770):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
10-03 00:23:39.250: E/WindowManager(1770):  at dalvik.system.NativeStart.main(Native Method)

NOTE – Webservice code is workingfFine without the Asynctask Task.
NOTE – Asynctask is working fine when doing time consuming calculations directly inside doInBackground method.

Just Tried this inside doInBackground method its working and implementing Webservice but now I got stuck in progressdialog.It wont go away.

if (Looper.myLooper() == null) { 
Looper.prepare(); 
} 
mLooper = Looper.myLooper(); resultofmail=sendtoserver(); 
Looper.loop(); 
return null; 
  • 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-12T09:36:27+00:00Added an answer on June 12, 2026 at 9:36 am

    The problem occurs when you try to show Toast when running sendtoserver() inside doInBackground().

    Instead, I would suggest you to re-arrange your code and return any error code from doInBackground() and show Toast inside onPostExecute() – which runs on UI thread.

    Or you may make use of runOnUiThread method which runs your Runnable on UI thread.

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

Sidebar

Related Questions

here is the code of the calling method - NameValuePair[] data = { new
I've got a quite strange problem here. I'm calling some simple code via Ajax.Updater:
Basically, here's my problem. I'm calling someone else's FORTRAN functions from my C++ code,
Here is the Delphi code calling the C++/CLI DLL: implementation {$R *.DFM} procedure CallMe(x:
I am calling a webservice from an AsyncTask. It works fine but i'm trying
Hi Calling my image code refresh using following code Here captchaController.do is the springController.
There’s a really cool diff class hosted by Google here: http://code.google.com/p/google-diff-match-patch/ I’ve used it
Here is the code I'm calling PropertyInfo targetColumn; targetColumn = targetType.GetProperty(CtrId); Here is the
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query

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.