Problem description: Server JSP, client android. After the server is released, the client can debug and receive the data sent from the server on the simulator, but the real machine cannot receive the data. An exception is reported: android. OS. NetworkOnMainThreadException.
Cause: the program executes network access on the main thread. in MySQL 4.0, the access network cannot be in the main program. This problem occurs when the network is connected to MySQL 3.0 or later. These are all the statements on the Internet. In short, thank you for your sharing ~~~
1. http://blog.csdn.net/dcl8261425/article/details/9181545
/AndroidRuntime (1185): android. OS. NetworkOnMainThreadException
This is because the program executes network access on the main thread. Can be reduced
Android: minSdkVersion = "8"
Android: targetSdkVersion = "8"/>
No exception is reported. But the best solution is to write the thread.
2. http://my.eoe.cn/iceskysl/archive/4382.html
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.share_mblog_view);
// Call new Thread (runnable ). start ();} Handler handler = new Handler () {@ Override public void handleMessage (Message msg) {super. handleMessage (msg); Bundle data = msg. getData (); String val = data. getString ("value"); Log. I ("mylog", "request result -->" + val) ;}} Runnable runnable = new Runnable () {@ Override public void run (){
// Write my request data code here
// Pass the value Message msg = new Message (); Bundle data = new Bundle (); data. putString ("value", "request result"); msg. setData (data); handler. sendMessage (msg );}}