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

  • Home
  • SEARCH
  • 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 8824945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:45:26+00:00 2026-06-14T06:45:26+00:00

My android application has a BroadcastReceiver . At start I start a Service that

  • 0

My android application has a BroadcastReceiver. At start I start a Service that has an AlarmManager for calling my receiver periodically every 10 minutes and the receiver tries to make a http connection. When the receiver is trying to make a httpConnection sometimes it takes times in lines httpConnection.getResponseCode(); or in androidHttpTransport.call(soapAction, envelope); and in these situations android UI (Activity) hangs and waits until the receiver’s operation is completed. But I think the BroadcastReceiver’s operation is in a separate thread and it should not pauses UI thread.

Why this happens and how can I correct it?

My httpconnection in receiver:

private Object callWebServiceMethodPublic(String url,
            String namespace, String methodName,
            HashMap<String, Object> parameters, String soapAction)
            throws Exception {

        //System.setProperty("http.keepAlive", "false");

        Log.i("WebService", "URL: " + url);
        Log.i("WebService", "MethodName: " + methodName);

        Log.i("SendMapMovements", "1.2.3.1");

        URL myurl = new URL(url);
        URLConnection connection = myurl.openConnection();
        connection.setConnectTimeout(20 * 1000);
        //connection.setRequestProperty("Connection", "close");

        HttpURLConnection httpConnection = (HttpURLConnection) connection;

        Log.i("SendMapMovements", "1.2.3.2");

        int responseCode = -1;
        try {
            responseCode = httpConnection.getResponseCode();

            Log.i("SendMapMovements", "1.2.3.3");

        } catch (Exception e1) {
            if (e1.toString().contains("Network is unreachable")) {

            } else if (e1.toString().contains("SocketTimeoutException")) {

            } else {
                throw e1;
            }
        }
        if (responseCode == HttpURLConnection.HTTP_OK) {
            httpConnection.disconnect();

            Log.i("SendMapMovements", "1.2.3.4");

            SoapObject request = new SoapObject(namespace, methodName);

            if (parameters != null) {
                String[] keys = new String[0];
                keys = (String[]) parameters.keySet().toArray(keys);
                Object[] vals = (Object[]) parameters.values().toArray();

                for (int i = 0; i < parameters.size(); i++) {
                    request.addProperty(keys[i], vals[i]);
                    Log.i("WebService", keys[i] + ": " + vals[i]);
                }
            }

            Log.i("SendMapMovements", "1.2.3.5");

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;

            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
                    TimeOutInSeconds * 1000);

            Log.i("SendMapMovements", "1.2.3.6");

            try {
                androidHttpTransport.call(soapAction, envelope);

                Log.i("SendMapMovements", "1.2.3.7");

            } catch (Exception e) {
                if (e.toString().contains("XmlPullParserException")) {
                    throw new Exception(...);
                }
            }

            Object so = envelope.getResponse();
            System.gc();

            return so;

        } else {
            httpConnection.disconnect();
            Log.i("SendMapMovements", "1.2.3.8");
            String strErrorDescription = getHttpErrorDescription(responseCode);
            throw new Exception(strErrorDescription);
        }
    }
  • 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-14T06:45:27+00:00Added an answer on June 14, 2026 at 6:45 am

    you must run your connection code whithin new Thread, not on UI Thread (Main Thread), because the BroadcastReceiver and your Activity runs on the same thread.

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

Sidebar

Related Questions

I have a application in Android that has a broadcast receiver that clear any
Greetings! I'm working on an application that has a BroadcastReceiver listening on android.intent.action.PHONE_STATE, which
I have an android application that has 3 activites. For the 1st and 2nd
I am trying to create a simple Android application that has a ActivityList of
My Android application has a form that the user has to fill in. I
My Android application has an ActionBar that changes which Fragment occupies a certain FrameLayout
My Android application has some files in the assets directory that I want to
I'm writing an Android application that has a scrollview which contains a linearlayout: <ScrollView
I have a TextView in my android application that has a set width on
I have an application that has a service to be conditionally started on boot

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.