Skip to content

Commit 89fa69c

Browse files
rafael-matsudaJeasmine
authored andcommitted
Fix NullPointerException on runOnMainThread
Fix the issue #190 using the same native Android SDK implementation. Importing libraries Handler and Looper Importing libraries Update FlutterRegistrarResponder.java
1 parent 8c9e51c commit 89fa69c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

android/src/main/java/com/onesignal/flutter/FlutterRegistrarResponder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.onesignal.flutter;
22

3+
import android.os.Handler;
4+
import android.os.Looper;
5+
36
import android.app.Activity;
47

58
import java.util.HashMap;
@@ -54,7 +57,12 @@ public void run() {
5457
}
5558

5659
private void runOnMainThread(final Runnable runnable) {
57-
((Activity) flutterRegistrar.activeContext()).runOnUiThread(runnable);
60+
if (Looper.getMainLooper().getThread() == Thread.currentThread())
61+
runnable.run();
62+
else {
63+
Handler handler = new Handler(Looper.getMainLooper());
64+
handler.post(runnable);
65+
}
5866
}
5967

6068
void invokeMethodOnUiThread(final String methodName, final HashMap map) {

0 commit comments

Comments
 (0)