我使用service读取蓝牙扫描枪数据,关闭service的时候出现了一些问题,系统老是自己从发出关闭service命令的activity,跳到另一个activity问题说明:activity发出一个命令,直接执行stopService()service代码://线程读取蓝牙数据
public class MyThread extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
while (flag) {
String value = ""; try {
bytes = inStream.read(buffer); for (int i = 0; i < bytes; i++) {
value += (char) buffer[i];
}
getCode(value);// 显示扫描码 } catch (IOException e1) {
// TODO Auto-generated catch block
stopService();
break;
} try {
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}//停止服务(问题出在这里)
public void stopService() {
// threadFlag = false;// 停止线程
if (myThread != null) {
app.setBlueConnectionFlag("未启动");// 蓝牙连接标志
connectFlag();
flag = false;
try {
btSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println(e.toString());
} try {
myThread.interrupt();
myThread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
unregisterReceiver(cmdReceiver);
} catch (Exception e1) {
// TODO Auto-generated catch block
System.out.println("unregisterReceiver" + e1.toString());
}
showToast("扫描已停止!");
} stopSelf();// 停止服务 }后台报错信息:
03-06 23:28:00.619: WARN/System.err(734): java.lang.InterruptedException
03-06 23:28:00.619: WARN/System.err(734):     at java.lang.Object.wait(Native Method)
03-06 23:28:00.619: WARN/System.err(734):     at java.lang.Object.wait(Object.java:288)
03-06 23:28:00.619: WARN/System.err(734):     at java.lang.Thread.join(Thread.java:983)
03-06 23:28:00.730: INFO/DEBUG(72): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
03-06 23:28:00.730: INFO/DEBUG(72): Build fingerprint: 'qcom/msm7627_ffa/msm7627_ffa/7x27:2.2.2/FRG83G/TBW590810_8030_V0224:user/release-keys'
03-06 23:28:00.730: INFO/DEBUG(72): pid: 734, tid: 742  >>> com.hosoft.mobile <<<
03-06 23:28:00.730: INFO/DEBUG(72): signal 11 (SIGSEGV), fault addr deadbaad
03-06 23:28:00.730: INFO/DEBUG(72):  r0 00000000  r1 0000000c  r2 00000027  r3 00000000
03-06 23:28:00.730: INFO/DEBUG(72):  r4 00000000  r5 deadbaad  r6 00001730  r7 40000000
03-06 23:28:00.730: INFO/DEBUG(72):  r8 470a3b78  r9 431b3e9c  10 431b3e88  fp 002442e0
03-06 23:28:00.730: INFO/DEBUG(72):  ip ffffffff  sp 470a3ad0  lr afd154d5  pc afd11dd4  cpsr 40000030
03-06 23:28:00.730: INFO/DEBUG(72):  d0  43a48000428c0000  d1  0000004643710000
03-06 23:28:00.730: INFO/DEBUG(72):  d2  4371000000000000  d3  3ff0000000000000
03-06 23:28:00.730: INFO/DEBUG(72):  d4  0000000000000000  d5  0000000000000000
03-06 23:28:00.739: INFO/DEBUG(72):  d6  00000000c2480000  d7  40c0000043a48000
03-06 23:28:00.739: INFO/DEBUG(72):  d8  0000000000000000  d9  0000000000000000
03-06 23:28:00.739: INFO/DEBUG(72):  d10 0000000000000000  d11 0000000000000000
03-06 23:28:00.739: INFO/DEBUG(72):  d12 0000000000000000  d13 0000000000000000
03-06 23:28:00.739: INFO/DEBUG(72):  d14 0000000000000000  d15 0000000000000000
03-06 23:28:00.739: INFO/DEBUG(72):  scr 20000012
03-06 23:28:00.789: INFO/DEBUG(72):          #00  pc 00011dd4  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):          #01  pc 0000be2c  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72): code around pc:
03-06 23:28:00.789: INFO/DEBUG(72): afd11db4 1c2bd00b 2d00682d e026d1fb 2b0068db 
03-06 23:28:00.789: INFO/DEBUG(72): afd11dc4 4e17d003 51a02001 4d164798 24002227 
03-06 23:28:00.789: INFO/DEBUG(72): afd11dd4 f7fb702a 2106ee14 ef10f7fc 05592380 
03-06 23:28:00.789: INFO/DEBUG(72): afd11de4 6091aa01 1c116054 94012006 eab6f7fc 
03-06 23:28:00.789: INFO/DEBUG(72): afd11df4 2200a905 f7fc2002 f7fbeac2 2106ee00 
03-06 23:28:00.789: INFO/DEBUG(72): code around lr:
03-06 23:28:00.789: INFO/DEBUG(72): afd154b4 b0834a0d 589c447b 26009001 686768a5 
03-06 23:28:00.789: INFO/DEBUG(72): afd154c4 220ce008 2b005eab 1c28d003 47889901 
03-06 23:28:00.789: INFO/DEBUG(72): afd154d4 35544306 d5f43f01 2c006824 b003d1ee 
03-06 23:28:00.789: INFO/DEBUG(72): afd154e4 bdf01c30 0002ae6c 000000d4 1c0fb5f0 
03-06 23:28:00.789: INFO/DEBUG(72): afd154f4 43551c3d a904b087 1c16ac01 604d9004 
03-06 23:28:00.789: INFO/DEBUG(72): stack:
03-06 23:28:00.789: INFO/DEBUG(72):     470a3a90  00000015  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3a94  afd1454b  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3a98  afd405a0  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3a9c  afd4054c  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3aa0  00000000  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3aa4  afd154d5  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3aa8  44f119b0  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
03-06 23:28:00.789: INFO/DEBUG(72):     470a3aac  afd1451d  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ab0  00000000  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ab4  afd40328  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ab8  00000000  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3abc  00001730  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ac0  40000000  /dev/ashmem/system_properties (deleted)
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ac4  afd147bb  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ac8  df002777  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3acc  e3a070ad  
03-06 23:28:00.789: INFO/DEBUG(72): #00 470a3ad0  470a3b78  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ad4  431b3e9c  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ad8  afd418e4  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3adc  afd10520  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ae0  afd40328  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ae4  fffffbdf  
03-06 23:28:00.789: INFO/DEBUG(72):     470a3ae8  afd40328  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3aec  afd4172c  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72):     470a3af0  0000a000  [heap]
03-06 23:28:00.789: INFO/DEBUG(72):     470a3af4  afd0be31  /system/lib/libc.so
03-06 23:28:00.789: INFO/DEBUG(72): #01 470a3af8  afd40328  /system/lib/libc.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3afc  afd0be31  /system/lib/libc.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b00  0000002a  
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b04  afa030b8  /system/lib/liblog.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b08  000000b8  
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b0c  470a3b20  
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b10  afa0109d  /system/lib/liblog.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b14  afa01195  /system/lib/liblog.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b18  00001404  
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b1c  002442e0  [heap]
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b20  00000001  
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b24  002442e0  [heap]
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b28  00243300  [heap]
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b2c  00243300  [heap]
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b30  aca3b041  /system/lib/libdvm.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b34  afd0cd91  /system/lib/libc.so
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b38  002442e0  [heap]
03-06 23:28:00.799: INFO/DEBUG(72):     470a3b3c  aca3b055  /system/lib/libdvm.so
03-06 23:28:01.149: INFO/ActivityManager(123): Process com.hosoft.mobile (pid 734) has died.
03-06 23:28:01.159: INFO/WindowManager(123): WIN DEATH: Window{4507bbe0 com.hosoft.mobile/com.hosoft.mobile.MobileNurseLogin paused=false}
03-06 23:28:01.159: INFO/WindowManager(123): WIN DEATH: Window{450d6328 com.hosoft.mobile/com.hosoft.patient.PatientListActivity paused=false}
03-06 23:28:01.159: INFO/WindowManager(123): WIN DEATH: Window{450df920 com.hosoft.mobile/com.hosoft.patient.PatientListActivity paused=false}
03-06 23:28:01.169: WARN/ActivityManager(123): Scheduling restart of crashed service com.hosoft.mobile/com.hosoft.util.BlueToothService in 20000ms
03-06 23:28:01.189: INFO/ActivityManager(123): Start proc com.hosoft.mobile for activity com.hosoft.mobile/.MobileNurseLogin: pid=743 uid=10067 gids={3003, 3001, 3002}
03-06 23:28:01.319: INFO/BootReceiver(123): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
03-06 23:28:01.669: INFO/UsageStats(123): Unexpected resume of com.hosoft.mobile while already resumed in com.hosoft.mobile
03-06 23:28:01.949: WARN/InputManagerService(123): Got RemoteException sending setActive(false) notification to pid 734 uid 10067
03-06 23:28:02.029: INFO/ActivityManager(123): Displayed activity com.hosoft.mobile/.MobileNurseLogin: 861 ms (total 861 ms)               谢谢!