我的活动正在将工作排队到 IntentService。当我调试时,代码似乎运行正常。当我运行时,我得到如下所示的 logcat 结果。我添加了一个thread.sleep(1000);
,但行为没有改变。我的假设是,基于 IntentService 文档,如果 IS 仍然处于活动状态,它将对第二个请求进行排队,如果它处于非活动状态,它将重新启动。因此,可以发出背靠背的 startService() 请求,而不用担心时间或带有状态的回调。
两种不同的意图、捆绑包和数组:
final int[] arSim1Config = new int[10];
arSim1Config[0] = 2;
arSim1Config[1] = 101;
arSim1Config[2] = (int)simStartTs;
arSim1Config[3] = simStopTs;
arSim1Config[4] = 20;
arSim1Config[5] = 70;
arSim1Config[6] = 40;
arSim1Config[7] = 8000;
arSim1Config[8] = 5000;
arSim1Config[9] = 17000;
// launch simulator threads using test parameters
Intent inStartSim = new Intent(this, SimService.class);
inStartSim.setAction("genData");
Bundle simBundle = new Bundle();
simBundle.putIntArray("simConfigAr",arSim1Config);
inStartSim.putExtras(simBundle);
startService(inStartSim);
final int[] arSim2Config = new int[10];
arSim2Config[0] = 2;
arSim2Config[1] = 102;
arSim2Config[2] = (int)simStartTs;
arSim2Config[3] = simStopTs;
arSim2Config[4] = 5;
arSim2Config[5] = 110;
arSim2Config[6] = 95;
arSim2Config[7] = 12000;
arSim2Config[8] = 5000;
rSim2Config[9] = 13000;
// launch simulator threads using test parameters
Intent inStartSim2 = new Intent(this, SimService.class);
inStartSim2.setAction("genData");
Bundle simBundle2 = new Bundle();
simBundle2.putIntArray("simConfigAr",arSim2Config);
inStartSim2.putExtras(simBundle2);
startService(inStartSim2);
日志猫:
01-30 17:11:34.706 4075-4075/com.smartmedtek.prj.smartmed03 I/art﹕ Not late-enabling -Xcheck:jni (already on)
01-30 17:11:34.821 4075-4075/com.smartmedtek.prj.smartmed03 W/ActivityThread﹕ Application com.smartmedtek.prj.smartmed03 is waiting for the debugger on port 8100...
01-30 17:11:34.831 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ Sending WAIT chunk
01-30 17:11:34.844 4075-4082/com.smartmedtek.prj.smartmed03 I/art﹕ Debugger is active
01-30 17:11:34.845 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ Debugger has connected
01-30 17:11:34.845 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.071 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.281 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.500 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.720 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.932 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.151 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.361 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.571 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.781 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.990 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.200 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.410 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.621 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ debugger has settled (1434)
01-30 17:11:37.979 4075-4075/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() No saved state available
01-30 17:11:38.049 4075-4095/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Render dirty regions requested: true
01-30 17:11:38.052 4075-4075/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6bdaf50, tid 4075
01-30 17:11:38.055 4075-4075/com.smartmedtek.prj.smartmed03 D/Atlas﹕ Validating map...
01-30 17:11:38.296 4075-4095/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa5f0a230, tid 4095
01-30 17:11:38.319 4075-4095/com.smartmedtek.prj.smartmed03 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-30 17:11:38.363 4075-4095/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Enabling debug mode 0
01-30 17:11:38.387 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:11:38.387 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f2a460, error=EGL_SUCCESS
01-30 17:11:38.451 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172712E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172717E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172722E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:54.971 4075-4096/com.smartmedtek.prj.smartmed03 E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[SimService]
Process: com.smartmedtek.prj.smartmed03, PID: 4075
java.lang.NullPointerException: Attempt to get length of null array
at com.smartmedtek.prj.smartmed03.SimService.onHandleIntent(SimService.java:117)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-30 17:11:55.057 4075-4075/com.smartmedtek.prj.smartmed03 I/Choreographer﹕ Skipped 995 frames! The application may be doing too much work on its main thread.
01-30 17:12:20.776 4075-4075/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() No saved state available
01-30 17:12:20.905 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:12:20.905 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f2a460, error=EGL_SUCCESS
01-30 17:12:21.184 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:12:21.184 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f9a9c0, error=EGL_SUCCESS
01-30 17:16:55.107 4075-4096/com.smartmedtek.prj.smartmed03 I/Process﹕ Sending signal. PID: 4075 SIG: 9
01-30 17:16:55.732 4123-4123/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() Restoring previous state
01-30 17:16:55.786 4123-4138/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Render dirty regions requested: true
01-30 17:16:55.846 4123-4123/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6c7d660, tid 4123
01-30 17:16:55.915 4123-4123/com.smartmedtek.prj.smartmed03 D/Atlas﹕ Validating map...
01-30 17:16:55.984 4123-4138/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6c7d950, tid 4138
01-30 17:16:56.084 4123-4138/com.smartmedtek.prj.smartmed03 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-30 17:16:56.111 4123-4138/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Enabling debug mode 0
01-30 17:16:56.138 4123-4138/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:16:56.138 4123-4138/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6caccc0, error=EGL_SUCCESS
01-30 17:16:56.471 4123-4138/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:16:56.472 4123-4138/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6cacdc0, error=EGL_SUCCESS
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045268E9
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045318E9
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045368E9
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.551 4123-4140/com.smartmedtek.prj.smartmed03 E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[SimService]
Process: com.smartmedtek.prj.smartmed03, PID: 4123
java.lang.NullPointerException: Attempt to get length of null array
at com.smartmedtek.prj.smartmed03.SimService.onHandleIntent(SimService.java:117)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-30 17:21:56.621 4123-4140/com.smartmedtek.prj.smartmed03 I/Process﹕ Sending signal. PID: 4123 SIG: 9
01-30 17:11:34.706 4075-4075/com.smartmedtek.prj.smartmed03 I/art﹕ Not late-enabling -Xcheck:jni (already on)
01-30 17:11:34.821 4075-4075/com.smartmedtek.prj.smartmed03 W/ActivityThread﹕ Application com.smartmedtek.prj.smartmed03 is waiting for the debugger on port 8100...
01-30 17:11:34.831 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ Sending WAIT chunk
01-30 17:11:34.844 4075-4082/com.smartmedtek.prj.smartmed03 I/art﹕ Debugger is active
01-30 17:11:34.845 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ Debugger has connected
01-30 17:11:34.845 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.071 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.281 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.500 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.720 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:35.932 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.151 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.361 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.571 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.781 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:36.990 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.200 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.410 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ waiting for debugger to settle...
01-30 17:11:37.621 4075-4075/com.smartmedtek.prj.smartmed03 I/System.out﹕ debugger has settled (1434)
01-30 17:11:37.979 4075-4075/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() No saved state available
01-30 17:11:38.049 4075-4095/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Render dirty regions requested: true
01-30 17:11:38.052 4075-4075/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6bdaf50, tid 4075
01-30 17:11:38.055 4075-4075/com.smartmedtek.prj.smartmed03 D/Atlas﹕ Validating map...
01-30 17:11:38.296 4075-4095/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa5f0a230, tid 4095
01-30 17:11:38.319 4075-4095/com.smartmedtek.prj.smartmed03 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-30 17:11:38.363 4075-4095/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Enabling debug mode 0
01-30 17:11:38.387 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:11:38.387 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f2a460, error=EGL_SUCCESS
01-30 17:11:38.451 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172712E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172717E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.02172722E9
01-30 17:11:38.452 4075-4096/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:11:54.971 4075-4096/com.smartmedtek.prj.smartmed03 E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[SimService]
Process: com.smartmedtek.prj.smartmed03, PID: 4075
java.lang.NullPointerException: Attempt to get length of null array
at com.smartmedtek.prj.smartmed03.SimService.onHandleIntent(SimService.java:117)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-30 17:11:55.057 4075-4075/com.smartmedtek.prj.smartmed03 I/Choreographer﹕ Skipped 995 frames! The application may be doing too much work on its main thread.
01-30 17:12:20.776 4075-4075/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() No saved state available
01-30 17:12:20.905 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:12:20.905 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f2a460, error=EGL_SUCCESS
01-30 17:12:21.184 4075-4095/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:12:21.184 4075-4095/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa5f9a9c0, error=EGL_SUCCESS
01-30 17:16:55.107 4075-4096/com.smartmedtek.prj.smartmed03 I/Process﹕ Sending signal. PID: 4075 SIG: 9
01-30 17:16:55.732 4123-4123/com.smartmedtek.prj.smartmed03 D/MainActivity﹕ onCreate() Restoring previous state
01-30 17:16:55.786 4123-4138/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Render dirty regions requested: true
01-30 17:16:55.846 4123-4123/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6c7d660, tid 4123
01-30 17:16:55.915 4123-4123/com.smartmedtek.prj.smartmed03 D/Atlas﹕ Validating map...
01-30 17:16:55.984 4123-4138/com.smartmedtek.prj.smartmed03 D/﹕ HostConnection::get() New Host Connection established 0xa6c7d950, tid 4138
01-30 17:16:56.084 4123-4138/com.smartmedtek.prj.smartmed03 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
01-30 17:16:56.111 4123-4138/com.smartmedtek.prj.smartmed03 D/OpenGLRenderer﹕ Enabling debug mode 0
01-30 17:16:56.138 4123-4138/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:16:56.138 4123-4138/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6caccc0, error=EGL_SUCCESS
01-30 17:16:56.471 4123-4138/com.smartmedtek.prj.smartmed03 W/EGL_emulation﹕ eglSurfaceAttrib not implemented
01-30 17:16:56.472 4123-4138/com.smartmedtek.prj.smartmed03 W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6cacdc0, error=EGL_SUCCESS
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045268E9
01-30 17:16:56.545 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045318E9
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/strmId val:﹕ 101.0
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/TS val:﹕ 1.022045368E9
01-30 17:16:56.546 4123-4140/com.smartmedtek.prj.smartmed03 D/ramp val:﹕ 70.0
01-30 17:16:56.551 4123-4140/com.smartmedtek.prj.smartmed03 E/AndroidRuntime﹕ FATAL EXCEPTION: IntentService[SimService]
Process: com.smartmedtek.prj.smartmed03, PID: 4123
java.lang.NullPointerException: Attempt to get length of null array
at com.smartmedtek.prj.smartmed03.SimService.onHandleIntent(SimService.java:117)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
01-30 17:21:56.621 4123-4140/com.smartmedtek.prj.smartmed03 I/Process﹕ Sending signal. PID: 4123 SIG: 9