从Android应用程序中,我使用Volley库来处理POST请求。 这些请求用于将数据发送到放置我的服务器和数据库的URL。 我使用以下代码,在4分钟的限制内完美运行。然后屏幕停止响应,应用程序停止运行。 有人可以帮我解决这个问题吗?
requestQueue = Volley.newRequestQueue(getApplicationContext());
String insertUrl = "http://192.168.1.16/html/emoncms/input/post.json?node=bdd&json={power:"
+ mHrmValue +"}&apikey=c8e78867509aa883a0fd23e323e966f1";
StringRequest request = new StringRequest(Request.Method.POST,
insertUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
System.out.println(response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(HRSActivity.this, "Error: " + error,
Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(request);
这是logcat:
02-18 09:30:33.024 11131-11143/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.024 11131-11143/no.nordicsemi.android.nrftoolbox D/dalvikvm: create new thread
02-18 09:30:33.024 11131-11143/no.nordicsemi.android.nrftoolbox D/dalvikvm: new thread created
02-18 09:30:33.024 11131-11143/no.nordicsemi.android.nrftoolbox D/dalvikvm: update thread list
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1493: interp stack at 0xbed9d000
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: init ref table
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: init mutex
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1493: created from interp
02-18 09:30:33.025 11131-11143/no.nordicsemi.android.nrftoolbox D/dalvikvm: start new thread
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1493: notify debugger
02-18 09:30:33.025 11131-16886/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1493 (Thread-10423): calling run()
02-18 09:30:33.374 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:1
02-18 09:30:33.379 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]EAGAIN in Recvfrom
02-18 09:30:33.380 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]read byte is 0
02-18 09:30:33.380 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:33.381 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:33.556 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:100
02-18 09:30:33.558 11131-16883/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:33.658 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothGatt: onNotify() - Device=F6:9C:E9:9F:32:D8 UUID=00002a19-0000-1000-8000-00805f9b34fb srvcType=0 srvcInstId=0 charInstId=0
02-18 09:30:33.658 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.658 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.659 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.659 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.660 11131-11193/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.675 11131-11144/no.nordicsemi.android.nrftoolbox D/BluetoothGatt: onNotify() - Device=F6:9C:E9:9F:32:D8 UUID=00002a37-0000-1000-8000-00805f9b34fb srvcType=0 srvcInstId=0 charInstId=0
02-18 09:30:33.676 11131-11144/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.676 11131-11144/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.676 11131-11144/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.676 11131-11144/no.nordicsemi.android.nrftoolbox D/BluetoothDevice: mAddress: F6:9C:E9:9F:32:D8
02-18 09:30:33.689 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.689 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create new thread
02-18 09:30:33.690 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
02-18 09:30:33.690 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: new thread created
02-18 09:30:33.690 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=1016KB)
02-18 09:30:33.691 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: update thread list
02-18 09:30:33.691 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1494: interp stack at 0xbeebd000
02-18 09:30:33.691 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: init ref table
02-18 09:30:33.691 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: init mutex
02-18 09:30:33.691 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1494: created from interp
02-18 09:30:33.691 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: start new thread
02-18 09:30:33.692 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1494: notify debugger
02-18 09:30:33.692 11131-16892/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1494 (Thread-10424): calling run()
02-18 09:30:33.692 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.693 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create new thread
02-18 09:30:33.695 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 1040384-byte stack: Out of memory
02-18 09:30:33.695 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: new thread created
02-18 09:30:33.695 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=1016KB)
02-18 09:30:33.698 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 1007616-byte stack: Out of memory
02-18 09:30:33.698 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=984KB)
02-18 09:30:33.700 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 974848-byte stack: Out of memory
02-18 09:30:33.701 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=952KB)
02-18 09:30:33.703 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 942080-byte stack: Out of memory
02-18 09:30:33.703 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=920KB)
02-18 09:30:33.705 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 909312-byte stack: Out of memory
02-18 09:30:33.706 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=888KB)
02-18 09:30:33.708 11131-11144/no.nordicsemi.android.nrftoolbox W/libc: pthread_create failed: couldn't allocate 876544-byte stack: Out of memory
02-18 09:30:33.708 11131-11144/no.nordicsemi.android.nrftoolbox E/dalvikvm: Thread creation failed (err=Success, stacksize=856KB)
02-18 09:30:33.710 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: update thread list
02-18 09:30:33.710 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1495: interp stack at 0x40000000
02-18 09:30:33.710 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: init ref table
02-18 09:30:33.710 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: init mutex
02-18 09:30:33.711 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1495: created from interp
02-18 09:30:33.711 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: start new thread
02-18 09:30:33.711 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1495: notify debugger
02-18 09:30:33.711 11131-16893/no.nordicsemi.android.nrftoolbox D/dalvikvm: threadid=1495 (Thread-10425): calling run()
02-18 09:30:33.712 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.714 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: Alloc and initialize a Thread struct fail
02-18 09:30:33.716 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.718 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: Alloc and initialize a Thread struct fail
02-18 09:30:33.721 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: create interp thread : stack size=128KB
02-18 09:30:33.723 11131-11144/no.nordicsemi.android.nrftoolbox D/dalvikvm: Alloc and initialize a Thread struct fail
02-18 09:30:33.781 11131-11131/no.nordicsemi.android.nrftoolbox I/System.out: ok
02-18 09:30:34.133 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:1
02-18 09:30:34.139 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]EAGAIN in Recvfrom
02-18 09:30:34.139 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]read byte is 0
02-18 09:30:34.140 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:34.141 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:34.260 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:100
02-18 09:30:34.261 11131-16893/no.nordicsemi.android.nrftoolbox I/System.out: [CDS]rx timeout:2500
02-18 09:30:34.299 11131-11131/no.nordicsemi.android.nrftoolbox I/System.out: ok
答案 0 :(得分:0)
logcat非常有用,因为它显示了内存分配问题。 我通过在onCreate()方法中移动requestQueue来解决问题。 它节省了内存,因为requestQueue只被调用一次。 它现在正常工作,没有时间限制。 非常感谢!