Seen on the Internet, I have also been encountered before:
1 04-26 14:36:14.663:e/androidruntime (10368): android.os.NetworkOnMainThreadException2 04-26 14:36:14.663:e/androidruntime (10368): at android.os.strictmode$androidblockguardpolicy.onnetwork ( strictmode.java:1117)3 but I configured <uses-permission android:name= in the manifest. Android.permission.INTERNET "/>
The cause of this error is that the code does not conform to the Android specification, meaning that the network operation is abnormal in the main thread.
The general time-consuming operation is not allowed in the main line thread direct operation, such as network operation, etc.
Generally need to open a sub-thread to access the network, and then through the handler to update the interface.
Of course, it is also possible to do this test operation, refer to add the following code:
1 @Override2 protected voidonCreate (Bundle savedinstancestate) {3Strictmode.setthreadpolicy (NewStrictMode.ThreadPolicy.Builder ()4 . Detectdiskreads ()5 . Detectdiskwrites ()6. Detectnetwork ()//or. Detectall () for all detectable problems7 . Penaltylog ()8 . Build ()); 9Strictmode.setvmpolicy (NewStrictMode.VmPolicy.Builder ()Ten. Detectleakedsqlliteobjects ()//probing SQLite database operations One. Penaltylog ()//Print Logcat A . Penaltydeath () - . Build ()); - Super. OnCreate (savedinstancestate); theSetcontentview (R.layout.activity_main);
Reference Original: http://www.apkbus.com/android-114524-1-1.html
"Android Notes" cannot be network-operated in the main thread