Android Honeycomb: NetworkOnMainThreadException even when using AsyncTask and no strict mode?

前端 未结 2 1627
灰色年华
灰色年华 2020-12-09 04:38

I run into a NetworkOnMainThreadException with my Android 3.0 app. Searching for a solution I found this, but if I understand this correctly, default setting would be that t

相关标签:
2条回答
  • 2020-12-09 04:58

    In Android Honeycomb StrictMode is enabled, turn it off adding the code on the onCreate() function...

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState); 
            setContentView(R.layout.main);       
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }
    
    0 讨论(0)
  • 2020-12-09 05:01

    StrictMode is turned on by default in Honeycomb.

    See say link specifically penaltyDeathOnNetwork(). I ran into a similar problem.

    0 讨论(0)
提交回复
热议问题