Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`

When I run this piece of code on Android 2.3.6, it works fine. On 4.0 I get a StrictMode exception. From some questions on SO, seems like you cant do network operations on the UI thread. But I am not doing any UI operation on the UI thread.

I am calling doBackground directly and not execute, since I need to check the return value of the doBackground. I guess the below should have worked.

What am I missing here ?

handler.postDelayed(new Runnable() { @Override public void run() { God.identityHash = (String) new SwitchServer((IActionBar) splashScreen, God.mCruiseOnServer, nameText, phoneNumberText) .doInBackground(null); if (!mIsBackButtonPressed && God.identityHash != null) { FlurryAgent.logEvent(God.TCACCEPTED_AND_REGISTERED); Intent intent = new Intent(SplashScreen.this, HomeScreen.class); SplashScreen.this.startActivity(intent); finish(); } else { Toast.makeText(splashScreen, "Unable to save your details. Please try again.", Toast.LENGTH_LONG).show(); God.setTermsAndConditions(splashScreen, false); } } }, SPLASH_DURATION);

Edit : Strict mode is not enabled on the phone.


Firstly, StrictMode is something you explicitly turned on from code, it is just a debugging aid, and should not be left on in production code.

Secondly, calling .doInBackground manually means running it on the UI thread. If you use AsyncTask as intended, you get its return value as a parameter in .onPostExecute.


  • In Python, how do I most efficiently chunk a UTF-8 string for REST delivery?
  • Concatenate Fields in Order - SQL Server
  • Static variables in Android
  • How to explode the string back from the second or third string delimiter?
  • Android label with self-updating time (hour and minute)
  • How do I make a splash screen load once?
  • How to Delay Execution of Code For X Amount of Time in Android
  • How do I periodically change background image?
  • Get current day's steps during datapointListener google Fit
  • VerifyInputWhenFocusTarget property has no effect
  • Implementing java gui login using multithreading
  • android-How to enable cache or buffering when videoView have downloaded a video
  • how to set id for each item in ListView
  • setContentView() is not enough to switch between layouts?
  • Galaxy S4 Android Custom Camera Issue
  • Separate ID and Class for JS and CSS
  • Android onKey w/ virtual keyboard
  • Laravel 4 routing not working due to .htaccess file?
  • netsh acl setting (need alternative method - registry settings?)
  • Regarding starting the threads on a condition
  • how to set variables in a php include file?
  • Implicit joins and Where in Doctrine - how?
  • Android Activity.onWindowFocusChanged doesn't get called from within TabHost
  • Button text different than value submitted in query string
  • Detect when Facebook like button is clicked
  • AJAX Html Editor Extender upload image appearing blank
  • Recording logins for password protected directories
  • Build own AppleScript numerical error handling
  • log4net write single file for each call to log.info
  • Why joiner is not used after Sequence generator or Update statergy
  • File not found error Google Drive API
  • Is it possible to post an object from jquery to bottle.py?
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • How can I use threading to 'tick' a timer to be accessed by other threads?