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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:48:54+00:00 2026-06-10T12:48:54+00:00

I am working on Network based project in android, so, to prevent force close

  • 0

I am working on Network based project in android, so, to prevent force close on Android ICS because of Can't do network operation on UI Thread , I must use the part of code such below or try to start my network operation on other thread, but I don’t want to change the base code, so I should use the code as below on Android ICS. :

static {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
    StrictMode.setThreadPolicy(policy);
}

How can I make unique apk file to run in all android version ( >= 1.6 ) ? android.os.StrictMode is accessible for higher version of android, so, i can not try to use the above part of code in my Android Activity. So, which solution is better :

  1. Using Reflections to run this part of code on higher versions of API (As oracle docs, reflective operations have slower performance than their non-reflective counterparts)
  2. Change my android build target to Android 4.1.1 (API 16) and try to change the android:minSdkVersion on AndroidManifest.xml

Or if you know any better ones, please let me know.

Thanks in advance 🙂

  • 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-10T12:48:55+00:00Added an answer on June 10, 2026 at 12:48 pm

    You can use BUILD.VERSION and reflection to get over this compability problem (tested).

        if (Integer.valueOf(android.os.Build.VERSION.SDK_INT) >= 9) {
            try {
                // StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
                Class<?> strictModeClass = Class.forName("android.os.StrictMode", true, Thread.currentThread()
                        .getContextClassLoader());
                Class<?> threadPolicyClass = Class.forName("android.os.StrictMode$ThreadPolicy", true, Thread.currentThread()
                        .getContextClassLoader());
                Field laxField = threadPolicyClass.getField("LAX");
                Method setThreadPolicyMethod = strictModeClass.getMethod("setThreadPolicy", threadPolicyClass);
                setThreadPolicyMethod.invoke(strictModeClass, laxField.get(null));
            } catch (Exception e) {
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a user based social network. I am building the site
I'm working on a network-related project and I am using DTLS (TLS/UDP) to secure
I am working on a a rails project based on social media networks. Is
I'm working on an Android game based on Playing Cards ( Bridge , to
Am making a basic phonegap based android app. All working perfectly and using localstorage
I'm working on a project creating a fairly simple one-to-many host-to-slave network using a
I am working on building an embedded network appliance (linux based) and have come
I am working on a social network type project, as most social networks have,
I am working on location based application for android .In that i want to
I'm working on a tool to automatically mount network volumes based on what wireless

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.