Skip to content

Commit

Permalink
Ensure all handlers are run on main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
SamJakob committed Jun 23, 2019
1 parent b502459 commit 40d5e21
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class DiscoveryRunningHandler implements EventChannel.StreamHandler {

public DiscoveryRunningHandler(){
this.handler = new Handler(Looper.getMainLooper());

}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
sink = eventSink;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package eu.sndr.fluttermdnsplugin.handlers;

import android.os.Handler;
import android.os.Looper;

import java.util.Map;

import io.flutter.plugin.common.EventChannel;

public class ServiceDiscoveredHandler implements EventChannel.StreamHandler {

private Handler handler;
EventChannel.EventSink sink;

public ServiceDiscoveredHandler(){
this.handler = new Handler(Looper.getMainLooper());
}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
sink = eventSink;
Expand All @@ -18,6 +27,6 @@ public void onCancel(Object o) {
}

public void onServiceDiscovered(Map<String, Object> serviceInfoMap){
sink.success(serviceInfoMap);
handler.post(() -> sink.success(serviceInfoMap));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package eu.sndr.fluttermdnsplugin.handlers;

import android.os.Handler;
import android.os.Looper;

import java.util.Map;

import io.flutter.plugin.common.EventChannel;

public class ServiceLostHandler implements EventChannel.StreamHandler {

private Handler handler;
EventChannel.EventSink sink;

public ServiceLostHandler(){
this.handler = new Handler(Looper.getMainLooper());
}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
sink = eventSink;
Expand All @@ -18,6 +27,6 @@ public void onCancel(Object o) {
}

public void onServiceLost(Map<String, Object> serviceInfoMap){
sink.success(serviceInfoMap);
handler.post(() -> sink.success(serviceInfoMap));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package eu.sndr.fluttermdnsplugin.handlers;

import android.os.Handler;
import android.os.Looper;

import java.util.Map;

import io.flutter.plugin.common.EventChannel;

public class ServiceResolvedHandler implements EventChannel.StreamHandler {

private Handler handler;
EventChannel.EventSink sink;

public ServiceResolvedHandler(){
this.handler = new Handler(Looper.getMainLooper());
}

@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
sink = eventSink;
Expand All @@ -18,7 +27,7 @@ public void onCancel(Object o) {
}

public void onServiceResolved(Map<String, Object> serviceInfoMap) {
sink.success(serviceInfoMap);
handler.post(() -> sink.success(serviceInfoMap));
}

}

0 comments on commit 40d5e21

Please sign in to comment.