Skip to content

Commit 4579305

Browse files
authored
Fixes Android crash react-native-component#49
1 parent 08293d1 commit 4579305

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

android/src/main/java/com/reactnativecomponent/splashscreen/RCTSplashScreen.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ protected static Activity getActivity() {
3131
return wr_activity.get();
3232
}
3333

34+
protected static boolean hasActivity() {
35+
return (wr_activity != null);
36+
}
37+
3438
public static void openSplashScreen(Activity activity) {
3539
openSplashScreen(activity, false);
3640
}
@@ -49,7 +53,7 @@ public static void openSplashScreen(final Activity activity, final boolean isFul
4953
activity.runOnUiThread(new Runnable() {
5054
public void run() {
5155

52-
if(!getActivity().isFinishing()) {
56+
if(hasActivity() && !getActivity().isFinishing()) {
5357
Context context = getActivity();
5458
imageView = new ImageView(context);
5559

@@ -78,9 +82,10 @@ public void run() {
7882
}
7983

8084
public static void removeSplashScreen(Activity activity, final int animationType,final int duration) {
81-
if (activity == null) {
85+
if (hasActivity()) {
8286
activity = getActivity();
83-
if(activity == null) return;
87+
} else {
88+
return;
8489
}
8590
activity.runOnUiThread(new Runnable() {
8691
public void run() {

0 commit comments

Comments
 (0)