Skip to content

Commit a1c8eba

Browse files
author
Douglas Nassif Roma Junior
committed
- Fixed runOnMainThread() bug
1 parent 854672f commit a1c8eba

File tree

1 file changed

+14
-6
lines changed
  • BluetoothClassicLibrary/src/main/java/com/github/douglasjunior/bluetoothclassiclibrary

1 file changed

+14
-6
lines changed

BluetoothClassicLibrary/src/main/java/com/github/douglasjunior/bluetoothclassiclibrary/BluetoothService.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,28 @@ public void run() {
5959
});
6060
}
6161

62-
protected void runOnMainThread(Runnable runnable, long delayMillis) {
62+
protected void runOnMainThread(final Runnable runnable, final long delayMillis) {
6363
if (mConfig.callListenersInMainThread) {
6464
if (delayMillis > 0) {
6565
handler.postDelayed(runnable, delayMillis);
6666
} else {
6767
handler.post(runnable);
6868
}
6969
} else {
70-
try {
71-
if (delayMillis > 0)
72-
Thread.sleep(delayMillis);
70+
if (delayMillis > 0) {
71+
new Thread() {
72+
@Override
73+
public void run() {
74+
try {
75+
Thread.sleep(delayMillis);
76+
runnable.run();
77+
} catch (InterruptedException e) {
78+
e.printStackTrace();
79+
}
80+
}
81+
}.start();
82+
} else {
7383
runnable.run();
74-
} catch (InterruptedException e) {
75-
e.printStackTrace();
7684
}
7785
}
7886
}

0 commit comments

Comments
 (0)