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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:04:40+00:00 2026-06-02T00:04:40+00:00

I have an intentservice which uploads data from phone to my server. Whenever network

  • 0

I have an intentservice which uploads data from phone to my server. Whenever network connection is available I start it from a broadcast receiver. It all works fine but when I test it by Android 4.0.3 emulator it gives strictmode error android.os.NetworkOnMainThreadException. It’s like this network job is on main thread but as far as I know intentservice has makes a worker thread. I found this link as well http://code.google.com/p/android/issues/detail?id=23495 which says move network job to background thread. Isn’t worker thread a background thread?

Edited: this is my broadcast receiver.

public void onReceive(Context context, Intent intent) {
    final String UploadingItems = "paUploadingItems";
    final String preferencesFileName = "paSettings";

    SharedPreferences sharedPref;   
    String fileQueque;

    if(isNetworkAvailable(context)){        

        sharedPref = context.getSharedPreferences(preferencesFileName,0);
        fileQueque = sharedPref.getString(UploadingItems, "");
        Log.d(TAG, "quque"+fileQueque);
        if(fileQueque.length() > 0){

                Intent intentUpdater = new Intent(context, updaterService.class);               
                intentUpdater.putExtra("processMode", 6);
                intentUpdater.putExtra("fileq", fileQueque.toString());
                context.startService(intentUpdater);

            }
    }       

}

private boolean isNetworkAvailable(Context context){
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();     
    Log.d(TAG, activeNetworkInfo.getTypeName());
    return (activeNetworkInfo != null && activeNetworkInfo.isAvailable() && activeNetworkInfo.isConnected());       

}

And this is the error I see in LogCat:

04-17 15:28:58.114: E/AndroidRuntime(574): FATAL EXCEPTION: main
04-17 15:28:58.114: E/AndroidRuntime(574): java.lang.RuntimeException: Unable to start     receiver org.test.dairy.OnNetworkReceiver: android.os.NetworkOnMainThreadException
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2126)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.app.ActivityThread.access$1500(ActivityThread.java:123)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.os.Looper.loop(Looper.java:137)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.app.ActivityThread.main(ActivityThread.java:4424)
04-17 15:28:58.114: E/AndroidRuntime(574):  at java.lang.reflect.Method.invokeNative(Native Method)
04-17 15:28:58.114: E/AndroidRuntime(574):  at java.lang.reflect.Method.invoke(Method.java:511)
04-17 15:28:58.114: E/AndroidRuntime(574):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-17 15:28:58.114: E/AndroidRuntime(574):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-17 15:28:58.114: E/AndroidRuntime(574):  at dalvik.system.NativeStart.main(Native Method)
04-17 15:28:58.114: E/AndroidRuntime(574): Caused by: android.os.NetworkOnMainThreadException
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
04-17 15:28:58.114: E/AndroidRuntime(574):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
04-17 15:28:58.114: E/AndroidRuntime(574):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
04-17 15:28:58.114: E/AndroidRuntime(574):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
04-17 15:28:58.114: E/AndroidRuntime(574):  at libcore.net.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:188)
04-17 15:28:58.114: E/AndroidRuntime(574):  at org.test.dairy.OnNetworkReceiver.transferData(OnNetworkReceiver.java:101)
04-17 15:28:58.114: E/AndroidRuntime(574):  at   org.test.dairy.OnNetworkReceiver.onReceive(OnNetworkReceiver.java:57)
04-17 15:28:58.114: E/AndroidRuntime(574):  at android.app.ActivityThread.handleReceiver(ActivityThread.java:2119)
04-17 15:28:58.114: E/AndroidRuntime(574):  ... 10 more
  • 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-02T00:04:41+00:00Added an answer on June 2, 2026 at 12:04 am

    Your isNetworkAvailable() method checks for network I/O on the main UI thread, and Android considers that blocking. I would just fire off the request to the IntentService without checking for connectivity in the Activity, and let the IntentService throw an exception and report back to the Activity if it can’t make a connection.

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

Sidebar

Related Questions

I have class that extends 'IntentService' - this class occasionally receives data from a
I have a Intent service which is called from either a receiver or an
i have this IntentService code which run a service once: protected void onHandleIntent(Intent intent)
Have one Doubt In MVC Architecture we can able to pass data from Controller
I have an IntentService which updates a preference like this: SharedPreferences.Editor editor = userPrefs.edit();
Good day, I have an activity which i navigate to from an icon on
I have an IntentService which queues up web service calls to be made. I
I have an IntentService which makes some web service calls. Before making these calls
I have an IntentService and I want to make it sticky with an ongoing
I have an IntentService that is parsing some xlm file to create a html

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.