Skip to content

Commit

Permalink
Support child thread in android
Browse files Browse the repository at this point in the history
  • Loading branch information
罗浩 committed Jul 1, 2020
1 parent cb7a64f commit a0117c9
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import android.net.TrafficStats;
import android.os.Handler;
import android.os.HandlerThread;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand All @@ -15,10 +16,12 @@
public class RNReactNativePingModule extends ReactContextBaseJavaModule {
private final String TIMEOUT_KEY = "timeout";
private final ReactApplicationContext reactContext;
HandlerThread handlerThread = new HandlerThread("HandlerThread");

public RNReactNativePingModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
handlerThread.start();
}

@ReactMethod
Expand All @@ -35,7 +38,9 @@ public void start(final String ipAddress, ReadableMap option, final Promise prom
timeout = option.getInt(TIMEOUT_KEY);
}
final int finalTimeout = timeout;
new Handler().post(new Runnable() {

Handler mHandler = new Handler(handlerThread.getLooper());
mHandler.post(new Runnable() {
@Override
public void run() {
try {
Expand All @@ -57,7 +62,7 @@ public void run() {
}
});

new Handler().postDelayed(new Runnable() {
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (isFinish[0]) {//Prevent multiple calls
Expand Down

0 comments on commit a0117c9

Please sign in to comment.