crazycodeboy / react-native-splash-screen

A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
MIT License
5.62k stars 1.1k forks source link

MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView #32

Open rmarquois opened 7 years ago

rmarquois commented 7 years ago

Hello.

When I start my app compiled in release mode I've got this error :

Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): android.view.WindowLeaked: Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
E/WindowManager(25826):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
E/WindowManager(25826):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager(25826):     at android.app.Dialog.show(Dialog.java:281)
E/WindowManager(25826):     at com.cboy.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32)
E/WindowManager(25826):     at android.app.Activity.runOnUiThread(Activity.java:4662)
E/WindowManager(25826):     at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:22)
E/WindowManager(25826):     at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:42)
E/WindowManager(25826):     at com.myapp.MainActivity.onCreate(MainActivity.java:11)
E/WindowManager(25826):     at android.app.Activity.performCreate(Activity.java:5122)
E/WindowManager(25826):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
E/WindowManager(25826):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
E/WindowManager(25826):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/WindowManager(25826):     at android.app.ActivityThread.access$600(ActivityThread.java:156)
E/WindowManager(25826):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
E/WindowManager(25826):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager(25826):     at android.os.Looper.loop(Looper.java:153)
E/WindowManager(25826):     at android.app.ActivityThread.main(ActivityThread.java:5299)
E/WindowManager(25826):     at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(25826):     at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(25826):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/WindowManager(25826):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/WindowManager(25826):     at dalvik.system.NativeStart.main(Native Method)

I fix it with the following code in the MainActivity.java :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
    }

    // my new code here
    @Override
    protected void onPause() {
      SplashScreen.hide(this);
      super.onPause();
    }

I can't confirm that it's the best solution but it works !

maxhalty commented 7 years ago

I'm having the same problem over here, I tried the solution that you suggested but it didn't work. Did you find something else? Any help would be great :)

maxhalty commented 7 years ago

Hi, if someone else have troubles with this maybe my experience help.

I tried a lot of things, and nothing worked until I found this steps for generating a release APK on React Native official documentation:

https://facebook.github.io/react-native/docs/signed-apk-android.html

I followed the step by step and tested the APK on my phone and now everything is working. I really don't understand why using './gradlew assembleRelease' and generating the signed APK with the Android Studio didn't work with the splash screen but with this other way of generating the APK worked perfectly.

I hope it helps.

manishoo commented 7 years ago

I'm having the same problem. v3.0.0

butchmarshall commented 7 years ago

Yep - hitting this issue. Works fine in development, happens when running signed production build.

"react-native-splash-screen": "^3.0.1",

bfinamore commented 6 years ago

Was anyone able to determine a root cause for this? What's odd is I'm only running into this issue with an obfuscated Proguard build (+ signed w/ release key). When I set -dontobfuscate in proguard-rules.pro and then compile the release with minifyEnabled true it works fine. I'm using version ^3.0.1 of this library.

CaviaTheGuineaPig commented 6 years ago

i'm having the same error :(

CaviaTheGuineaPig commented 6 years ago

if your method is onBackPressed, then delete the super.onBackPressed(); :D

brunolemos commented 6 years ago

I'm having this issue on Android even on Debug mode. Works fine on iOS. react-native 0.52.2 react-native-navigation 1.1.365 react-native-splash-screen 3.0.6 Android emulator API 26

E/WindowManager: android.view.WindowLeaked: 
Activity com.xapps.x.MainActivity has leaked window DecorView@4c2ceb2[] that was originally added here
    at android.view.ViewRootImpl.<init>(ViewRootImpl.java:485)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
    at android.app.Dialog.show(Dialog.java:330)
    at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36)
    at android.app.Activity.runOnUiThread(Activity.java:6152)
    at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:26)
    at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:47)
    at com.xapps.x.MainActivity.onCreate(MainActivity.java:14)
    at android.app.Activity.performCreate(Activity.java:6975)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
    at android.os.Handler.dispatchMessage(Handler.java:105)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
02-01 00:08:58.704 16422-16422/com.xapps.x E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.xapps.x, PID: 16422
                    java.lang.IllegalArgumentException: View=DecorView@4c2ceb2[] not attached to window manager
                        at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:485)
brunolemos commented 6 years ago

Adding this method works!

    @Override
    protected void onPause() {
        SplashScreen.hide(this);
        super.onPause();
    }

Thanks @rmarquois.

duongntb94 commented 6 years ago

After 2 hours of research. Above the problem : android.view.WindowLeaked: Activity com.xxx.MainActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{b2059e6 V.E...... R.....ID 0,0-2048,1536} that was originally added here

I found that this error: FATAL EXCEPTION: Thread-170 Process: com.xxx, PID: 1734 java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server. at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method) at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216) at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:33) at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:234) at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1137) at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:113) at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:944) at java.lang.Thread.run(Thread.java:818)

So after I tried to run the script below, I can install the release apk on my device. mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

noahtallen commented 6 years ago

@brunolemos I was trying to run debug from Android Studio as well! The onPause fixed it for me. I think it was because there's a point where the app shows "waiting for remote debugger to connect" (e.g. connecting to Android Studio), and the crash happened before right before that. I bet Android "paused" the activity while connecting to the debugger, resulting in some sort of error within the splash screen library.

mmazzarolo commented 6 years ago

Hey! We're having this issue in production.
Any reason why the following change haven't already been added to the lib?

@Override
protected void onPause() {
    SplashScreen.hide(this);
    super.onPause();
}

Is a PR needed? (I see there are a bunch of open PRs)

Thanks!

katwal-dipak commented 6 years ago

> Was anyone able to determine a root cause for this? What's odd is I'm only running into this issue with an obfuscated Proguard build (+ signed w/ release key). When I set -dontobfuscate in proguard-rules.pro and then compile the release with minifyEnabled true it works fine. I'm using version ^3.0.1 of this library.

It works fine with enableProguardInReleaseBuilds = true in release mode without setting -dontobfuscate in proguard-rules.pro with version 3.1.1.

@duongntb94 solution should fix above mentioned issue.

steventnorris-40AU commented 6 years ago

I am getting this error as well, even after adding the onPause method. Any solution here?

Using version 3.1.1 with React Native 0.55

public class MainActivity extends NavigationActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
  }

    @Override
    protected void onPause() {
        SplashScreen.hide(this);
        super.onPause();
    }

}
adrianolsk commented 6 years ago

After 2 hours of research.

So after I tried to run the script below, I can install the release apk on my device. mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

@duongntb94, that worked, thanks

HishamMubarak commented 6 years ago

After 2 hours of research.

So after I tried to run the script below, I can install the release apk on my device. mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

@duongntb94 , This fixed it. thanks a lot.

rupalpatel0008 commented 5 years ago

Tried both solutions mentioned here.

Adding this method works!

    @Override
    protected void onPause() {
        SplashScreen.hide(this);
        super.onPause();
    }

Thanks @rmarquois.

After 2 hours of research.

So after I tried to run the script below, I can install the release apk on my device. mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

@duongntb94 , This fixed it. thanks a lot.

Manoj002 commented 5 years ago

android app crashes everytime, tried almost everything out there on internet, nothing is wokring... :-|

HishamMubarak commented 5 years ago

android app crashes everytime, tried almost everything out there on internet, nothing is wokring... :-|

Run the app from within android studio and check and logs. See what the issue is and paste the red color issue you found, in here. Someone might be able to help

Manoj002 commented 5 years ago

@HishamMubarak Got it working... Just before generating apk run this command: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

hpmax00 commented 5 years ago

I am getting this error as well, even after adding the onPause method. Any solution here?

Using version 3.1.1 with React Native 0.55

public class MainActivity extends NavigationActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
  }

    @Override
    protected void onPause() {
        SplashScreen.hide(this);
        super.onPause();
    }

}

I have the same problem, it caused by another package. After deleting the package, I solve it.

bharatidudhrejiya commented 5 years ago

Any of this solution not working for me for android "Pie" There is any one have other solution.

Thanks!

rumax commented 5 years ago

After deleting the package, I solve it.

Which package did you delete and in which package it happened?

mtx62 commented 5 years ago

+1

Avery246813579 commented 5 years ago

I was getting this error when I was trying to run a production apk. It would throw onShow not on startup. This error is thrown when something goes wrong within your application. For me I never asked for the fine location permission and when trying to access the user's location the app would crash. I would suggest using Logcat in the Android Studio terminal and look around for errors. It's usually above the splash screen error.

konstantin-shkel commented 5 years ago

In addition to @duongntb94 solution

I think this answer on StackOverflow will be useful :) https://stackoverflow.com/a/46363228

Looks like a proper way to do it automatically rather than manually.

Also, you can look into a comment in android/app/build.gradle file. There you can find a bit more information about ext.react configuration

SkyTreasure commented 5 years ago

I tried all the methods mentioned here added onPause() , executed the following command

mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

still getting the same error.

android.view.WindowLeaked: Activity com.io.proathlix.MainActivity has leaked window DecorView@27f75e5[] that was originally added here at android.view.ViewRootImpl.<init>(ViewRootImpl.java:518) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:338) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at android.app.Dialog.show(Dialog.java:328) at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36) at android.app.Activity.runOnUiThread(Activity.java:5879) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49) at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:56) at com.io.proathlix.MainActivity.onCreate(MainActivity.java:16) at android.app.Activity.performCreate(Activity.java:6692) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2709) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2825) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1557) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:203) at android.app.ActivityThread.main(ActivityThread.java:6339) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1084) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:945)

Am on 3.1.1 version. Anyone else faced this problem and resolved by any other methods?

SkyTreasure commented 5 years ago

Updated to 3.2.0 fixed the issue for me.

thush5884 commented 5 years ago

make sure that you close the metro bundler and run it again, if you've been working on two react native projects you may have left metro bundler of some other package running. this is what happened to me.

sabun123 commented 5 years ago

I was getting this error when I was trying to run a production apk. It would throw onShow not on startup. This error is thrown when something goes wrong within your application. For me I never asked for the fine location permission and when trying to access the user's location the app would crash. I would suggest using Logcat in the Android Studio terminal and look around for errors. It's usually above the splash screen error.

Just wanted to say thanks for this. I was getting the error as well about windowLeaked, but the real error was way above it.

I'm using React Native 0.57.3 with react-native-splash-screen 3.1.1.

I had added buildTypes (for making different build variants of my app), and when making a signed app using any of those variants it would crash. It would work with release though, and that turns out to be due to the default behaviour that react will bundle your assets automatically for release without any config from you, but any other variants have to be managed by yourself.

I was getting the error:

2019-04-04 00:44:11.722 3892-3892/? E/WindowManager: android.view.WindowLeaked: Activity com.appmaster.MainActivity has leaked window DecorView@56c6dc3[] that was originally added here
        at android.view.ViewRootImpl.<init>(ViewRootImpl.java:417)
        at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:331)
        at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
        at android.app.Dialog.show(Dialog.java:316)
        at org.devio.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:36)
        at android.app.Activity.runOnUiThread(Activity.java:5849)
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:27)
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:49)
        at org.devio.rn.splashscreen.SplashScreen.show(SplashScreen.java:56)
        at com.appmaster.MainActivity.onCreate(MainActivity.java:11)
        at android.app.Activity.performCreate(Activity.java:6662)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Scrolling further above this error in logcat inside Android Studio revealed there was a smaller but main reason for the crash on start. Running this in the virtual emulator. (Crash happened on device too)

2019-04-04 00:51:58.670 4183-4201/? E/AndroidRuntime: FATAL EXCEPTION: Thread-2
    Process: com.appmaster.dev, PID: 4183
    java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:32)
        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:243)
        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1114)
        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:913)
        at java.lang.Thread.run(Thread.java:761)

Basically, it's saying it can't find any of the required assets since they weren't bundled so the app exits. Turns out there's nothing wrong with react-native-splash-screen.

I noticed in my build folder under android/app/build/intermediates/merged_assets for release that there is a index.android.bundle:

Screenshot 2019-04-04 at 1 08 42 AM

However, my build variant for dev didn't have this (which is the reason for the above error):

Screenshot 2019-04-04 at 1 04 32 AM

My added buildType looks like the following (in /android/app/build.gradle):

buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
// dev is my added buildType
        dev {
            initWith release
            applicationIdSuffix ".dev"
            matchingFallbacks = ['release']
        }
}

The solution was to add the following to the top of /android/app/build.gradle before the apply statement :

project.ext.react = [
    entryFile: "index.js",
    bundleInDev: true,
    jsBundleDirdev: "$buildDir/intermediates/merged_assets/dev/mergeDevAssets/out",
]

Note that bundleInDev needs to have the first letter of your buildType name capital, or it won't work. When I tried bundleIndev it failed, it needs to be capital. This tells react that we are bundling our assets for this build variant.

The second one is jsBundleDirdev. Strangely, this one works even if named jsBundleDirDev. This one tells react where to put the bundle (named index.android.bundle).

After doing this, my problem was solved. Running Generate Signed Bundle / APK worked for my dev variant, and starting up the app no longer crashes. The file index.android.bundle was being added for dev.

Basically, this will happen if you try to build a signed bundled version of debug too apparently, since it's set to bundleInDebug: false by default from what I can see.

Hopefully this helps someone else, or points someone closer to the right direction for their problem.

Malikkhoja-zz commented 5 years ago

I tried all the above answers, none of them worked for me. I am using RN 0.59.3 and Splash Screen 3.2.0. The same warning crashes the app with or without dontobfuscate.

Can anyone help?

Thanks in advance

onyand commented 4 years ago

The way I got around this issue is by not calling intent within a dialog. Below is one approach. **** use syntax applicable to activity or fragment accordingly

@Override public void onClick(DialogInterface dialog, int which) { checkvariable= true; getActivity().finish(); } @Override public void onStop() { super.onStop(); if (checkvariable) { startActivity(intent); } }

onyand commented 4 years ago

Hi,

I assume the error occurs immediately your snackbar shows. If that is the case, I suggest that you should not iniate the startActivity within the snack bar. Since you have invoked, finish() in the snackbar, I suggest you move the startActivity method to onStop() method

Regards, D.O.


From: NoxDRaz notifications@github.com Sent: Wednesday, May 20, 2020 11:58 AM To: crazycodeboy/react-native-splash-screen react-native-splash-screen@noreply.github.com Cc: onyand onyango.oduor.david@outlook.com; Comment comment@noreply.github.com Subject: Re: [crazycodeboy/react-native-splash-screen] MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView (#32)

I am facing a similar issue. Here is the error: https://i.stack.imgur.com/oTbXR.png

And my code: `//Google Sign In @overridehttps://github.com/override protected void onActivityResult(int requestCode, int resultCode, @nullablehttps://github.com/nullable Intent data) { super.onActivityResult(requestCode, resultCode, data);

if (requestCode == GOOGLE_SIGN_IN_KEY) { Task task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account);

} catch (ApiException e) {
    if (e.getStatusCode() == 12500) {
        Snackbar.make(findViewById(android.R.id.content), "Sign In Error! Update Google Play Service.", Snackbar.LENGTH_LONG).show();
    }
}

}

}

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); firebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener() { @overridehttps://github.com/override public void onComplete(@nonnullhttps://github.com/nonnull Task task) { if (task.isSuccessful()) { FirebaseUser user = firebaseAuth.getCurrentUser(); showGoogleSignUpDialog(); storeUserInfo(user.getPhotoUrl().toString(), user.getUid(), user.getDisplayName(), user.getEmail()); } else { Snackbar.make(findViewById(android.R.id.content), "Sign In Failed!", Snackbar.LENGTH_LONG).show(); } } }); }

private void storeUserInfo(final String stringUserImage, final String stringUserID, final String stringName, final String stringEmail) { FirebaseUser user = firebaseAuth.getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(stringName) .setPhotoUri(Uri.parse(stringUserImage)) .build();

user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { if (task.isSuccessful()) { firebaseFirestore.collection("UserData").document(stringUserID).get().addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(DocumentSnapshot documentSnapshot) { if (documentSnapshot.getData() != null && documentSnapshot.getData().size() > 0) { Snackbar.make(findViewById(android.R.id.content), "Welcome back!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class)); finish();

                        } else {
                            createUserData(stringUserID, stringUserImage, stringName, stringEmail);
                        }
                    }
                });
            }
        }
    });

}

private void createUserData(String stringUserID, String stringUserImage, String stringName, String stringEmail) { final Map<String, Object> userDataMap = new HashMap<>(); userDataMap.put("userName", stringName); userDataMap.put("userImage", stringUserImage); userDataMap.put("userID", stringUserID); userDataMap.put("userPoints", 100); userDataMap.put("userVerified", true); userDataMap.put("userEmail", stringEmail); userDataMap.put("timestamp", FieldValue.serverTimestamp());

firebaseFirestore.collection("UserData").document(stringUserID).set(userDataMap) .addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(Void aVoid) { new Handler().postDelayed(new Runnable() { @Override public void run() { alertGoogleSignIn.dismiss(); Snackbar.make(findViewById(android.R.id.content), "Welcome!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class).putExtra("canShowCoinCredit", true)); finish(); } }, 3000); } });

}

private void showGoogleSignUpDialog() { final AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Signing in"); alert.setMessage("Please hold on while we process..."); alert.setCancelable(false); alertGoogleSignIn = alert.create(); alertGoogleSignIn.show(); }`

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/crazycodeboy/react-native-splash-screen/issues/32#issuecomment-631340707, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZYSRTAYKLXH467OT3RMDTRSOLSJANCNFSM4DA53D3A.

rishi615 commented 4 years ago

Hi, I assume the error occurs immediately your snackbar shows. If that is the case, I suggest that you should not iniate the startActivity within the snack bar. Since you have invoked, finish() in the snackbar, I suggest you move the startActivity method to onStop() method Regards, D.O. ____ From: NoxDRaz notifications@github.com Sent: Wednesday, May 20, 2020 11:58 AM To: crazycodeboy/react-native-splash-screen react-native-splash-screen@noreply.github.com Cc: onyand onyango.oduor.david@outlook.com; Comment comment@noreply.github.com Subject: Re: [crazycodeboy/react-native-splash-screen] MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView (#32) I am facing a similar issue. Here is the error: https://i.stack.imgur.com/oTbXR.png And my code: //Google Sign In @override<https://github.com/override> protected void onActivityResult(int requestCode, int resultCode, @nullable<https://github.com/nullable> Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GOOGLE_SIGN_IN_KEY) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { if (e.getStatusCode() == 12500) { Snackbar.make(findViewById(android.R.id.content), "Sign In Error! Update Google Play Service.", Snackbar.LENGTH_LONG).show(); } } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); firebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener() { @override<https://github.com/override> public void onComplete(@nonnull<https://github.com/nonnull> Task task) { if (task.isSuccessful()) { FirebaseUser user = firebaseAuth.getCurrentUser(); showGoogleSignUpDialog(); storeUserInfo(user.getPhotoUrl().toString(), user.getUid(), user.getDisplayName(), user.getEmail()); } else { Snackbar.make(findViewById(android.R.id.content), "Sign In Failed!", Snackbar.LENGTH_LONG).show(); } } }); } private void storeUserInfo(final String stringUserImage, final String stringUserID, final String stringName, final String stringEmail) { FirebaseUser user = firebaseAuth.getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(stringName) .setPhotoUri(Uri.parse(stringUserImage)) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener<Void>() { @override public void onComplete(@nonnull Task<Void> task) { if (task.isSuccessful()) { firebaseFirestore.collection("UserData").document(stringUserID).get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() { @override public void onSuccess(DocumentSnapshot documentSnapshot) { if (documentSnapshot.getData() != null && documentSnapshot.getData().size() > 0) { Snackbar.make(findViewById(android.R.id.content), "Welcome back!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class)); finish(); } else { createUserData(stringUserID, stringUserImage, stringName, stringEmail); } } }); } } }); } private void createUserData(String stringUserID, String stringUserImage, String stringName, String stringEmail) { final Map<String, Object> userDataMap = new HashMap<>(); userDataMap.put("userName", stringName); userDataMap.put("userImage", stringUserImage); userDataMap.put("userID", stringUserID); userDataMap.put("userPoints", 100); userDataMap.put("userVerified", true); userDataMap.put("userEmail", stringEmail); userDataMap.put("timestamp", FieldValue.serverTimestamp()); firebaseFirestore.collection("UserData").document(stringUserID).set(userDataMap) .addOnSuccessListener(new OnSuccessListener<Void>() { @override public void onSuccess(Void aVoid) { new Handler().postDelayed(new Runnable() { @override public void run() { alertGoogleSignIn.dismiss(); Snackbar.make(findViewById(android.R.id.content), "Welcome!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class).putExtra("canShowCoinCredit", true)); finish(); } }, 3000); } }); } private void showGoogleSignUpDialog() { final AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Signing in"); alert.setMessage("Please hold on while we process..."); alert.setCancelable(false); alertGoogleSignIn = alert.create(); alertGoogleSignIn.show(); } — You are receiving this because you commented. Reply to this email directly, view it on GitHub<#32 (comment)>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZYSRTAYKLXH467OT3RMDTRSOLSJANCNFSM4DA53D3A.

I don't understand. Please see my problem here: https://stackoverflow.com/questions/61908287/startup-activitylogin-has-leaked-window-decorview3a9e526activitylogin-that-wa

onyand commented 4 years ago

I have responded against the stackoverflow link you have shared


From: NoxDRaz notifications@github.com Sent: Wednesday, May 20, 2020 2:16 PM To: crazycodeboy/react-native-splash-screen react-native-splash-screen@noreply.github.com Cc: onyand onyango.oduor.david@outlook.com; Comment comment@noreply.github.com Subject: Re: [crazycodeboy/react-native-splash-screen] MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView (#32)

Hi, I assume the error occurs immediately your snackbar shows. If that is the case, I suggest that you should not iniate the startActivity within the snack bar. Since you have invoked, finish() in the snackbar, I suggest you move the startActivity method to onStop() method Regards, D.O. … ____ From: NoxDRaz notifications@github.commailto:notifications@github.com Sent: Wednesday, May 20, 2020 11:58 AM To: crazycodeboy/react-native-splash-screen react-native-splash-screen@noreply.github.commailto:react-native-splash-screen@noreply.github.com Cc: onyand onyango.oduor.david@outlook.commailto:onyango.oduor.david@outlook.com; Comment comment@noreply.github.commailto:comment@noreply.github.com Subject: Re: [crazycodeboy/react-native-splash-screen] MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView (#32https://github.com/crazycodeboy/react-native-splash-screen/issues/32) I am facing a similar issue. Here is the error: https://i.stack.imgur.com/oTbXR.png And my code: //Google Sign In @overridehttps://github.com/override protected void onActivityResult(int requestCode, int resultCode, @nullablehttps://github.com/nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == GOOGLE_SIGN_IN_KEY) { Task task = GoogleSignIn.getSignedInAccountFromIntent(data); try { GoogleSignInAccount account = task.getResult(ApiException.class); firebaseAuthWithGoogle(account); } catch (ApiException e) { if (e.getStatusCode() == 12500) { Snackbar.make(findViewById(android.R.id.content), "Sign In Error! Update Google Play Service.", Snackbar.LENGTH_LONG).show(); } } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); firebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener() { @overridehttps://github.com/override public void onComplete(@nonnullhttps://github.com/nonnull Task task) { if (task.isSuccessful()) { FirebaseUser user = firebaseAuth.getCurrentUser(); showGoogleSignUpDialog(); storeUserInfo(user.getPhotoUrl().toString(), user.getUid(), user.getDisplayName(), user.getEmail()); } else { Snackbar.make(findViewById(android.R.id.content), "Sign In Failed!", Snackbar.LENGTH_LONG).show(); } } }); } private void storeUserInfo(final String stringUserImage, final String stringUserID, final String stringName, final String stringEmail) { FirebaseUser user = firebaseAuth.getCurrentUser(); UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder() .setDisplayName(stringName) .setPhotoUri(Uri.parse(stringUserImage)) .build(); user.updateProfile(profileUpdates) .addOnCompleteListener(new OnCompleteListener() { @override public void onComplete(@nonnull Task task) { if (task.isSuccessful()) { firebaseFirestore.collection("UserData").document(stringUserID).get().addOnSuccessListener(new OnSuccessListener() { @override public void onSuccess(DocumentSnapshot documentSnapshot) { if (documentSnapshot.getData() != null && documentSnapshot.getData().size() > 0) { Snackbar.make(findViewById(android.R.id.content), "Welcome back!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class)); finish(); } else { createUserData(stringUserID, stringUserImage, stringName, stringEmail); } } }); } } }); } private void createUserData(String stringUserID, String stringUserImage, String stringName, String stringEmail) { final Map<String, Object> userDataMap = new HashMap<>(); userDataMap.put("userName", stringName); userDataMap.put("userImage", stringUserImage); userDataMap.put("userID", stringUserID); userDataMap.put("userPoints", 100); userDataMap.put("userVerified", true); userDataMap.put("userEmail", stringEmail); userDataMap.put("timestamp", FieldValue.serverTimestamp()); firebaseFirestore.collection("UserData").document(stringUserID).set(userDataMap) .addOnSuccessListener(new OnSuccessListener() { @override public void onSuccess(Void aVoid) { new Handler().postDelayed(new Runnable() { @override public void run() { alertGoogleSignIn.dismiss(); Snackbar.make(findViewById(android.R.id.content), "Welcome!", Snackbar.LENGTH_LONG).show(); startActivity(new Intent(ActivityLogin.this, ActivityHome.class).putExtra("canShowCoinCredit", true)); finish(); } }, 3000); } }); } private void showGoogleSignUpDialog() { final AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Signing in"); alert.setMessage("Please hold on while we process..."); alert.setCancelable(false); alertGoogleSignIn = alert.create(); alertGoogleSignIn.show(); } — You are receiving this because you commented. Reply to this email directly, view it on GitHub<#32 (comment)https://github.com/crazycodeboy/react-native-splash-screen/issues/32#issuecomment-631340707>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZYSRTAYKLXH467OT3RMDTRSOLSJANCNFSM4DA53D3A.

I don't understand. Please see my problem here: https://stackoverflow.com/questions/61908287/startup-activitylogin-has-leaked-window-decorview3a9e526activitylogin-that-wa

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/crazycodeboy/react-native-splash-screen/issues/32#issuecomment-631411048, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADZYSRV6GZGSNGAO5PVR5S3RSO32NANCNFSM4DA53D3A.

rishi615 commented 4 years ago

Yes I replied there. But I am not getting that error in the logcat anymore. My actual issue from the start was not able to sign in with google. It works perfectly in the debug version as well as in the release apk version. But when I upload the apk bundle to the playstore, and install the app through playstore the sign in stops working for some reason. I have added both debug and release SHA-1 and SHA-256 in the firebase app. Don't know what's wrong. I am frustrated since yesterday. I am still new to android so I don't know much about everything.

BiplovQss commented 3 years ago

Tried both solutions mentioned here.

Adding this method works!

    @Override
    protected void onPause() {
        SplashScreen.hide(this);
        super.onPause();
    }

Thanks @rmarquois.

After 2 hours of research.

So after I tried to run the script below, I can install the release apk on my device. mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

@duongntb94 , This fixed it. thanks a lot.

thanks. It helped a lot.

abbasmoosavi commented 3 years ago

Hello.

When I start my app compiled in release mode I've got this error :

Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826): android.view.WindowLeaked: Activity com.myapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{415ceea8 V.E..... R.....I. 0,0-1024,552} that was originally added here
E/WindowManager(25826):   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
E/WindowManager(25826):   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
E/WindowManager(25826):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
E/WindowManager(25826):   at android.app.Dialog.show(Dialog.java:281)
E/WindowManager(25826):   at com.cboy.rn.splashscreen.SplashScreen$1.run(SplashScreen.java:32)
E/WindowManager(25826):   at android.app.Activity.runOnUiThread(Activity.java:4662)
E/WindowManager(25826):   at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:22)
E/WindowManager(25826):   at com.cboy.rn.splashscreen.SplashScreen.show(SplashScreen.java:42)
E/WindowManager(25826):   at com.myapp.MainActivity.onCreate(MainActivity.java:11)
E/WindowManager(25826):   at android.app.Activity.performCreate(Activity.java:5122)
E/WindowManager(25826):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
E/WindowManager(25826):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
E/WindowManager(25826):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358)
E/WindowManager(25826):   at android.app.ActivityThread.access$600(ActivityThread.java:156)
E/WindowManager(25826):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340)
E/WindowManager(25826):   at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager(25826):   at android.os.Looper.loop(Looper.java:153)
E/WindowManager(25826):   at android.app.ActivityThread.main(ActivityThread.java:5299)
E/WindowManager(25826):   at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(25826):   at java.lang.reflect.Method.invoke(Method.java:511)
E/WindowManager(25826):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
E/WindowManager(25826):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
E/WindowManager(25826):   at dalvik.system.NativeStart.main(Native Method)

I fix it with the following code in the MainActivity.java :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
      SplashScreen.show(this);
      super.onCreate(savedInstanceState);
    }

    // my new code here
    @Override
    protected void onPause() {
      SplashScreen.hide(this);
      super.onPause();
    }

I can't confirm that it's the best solution but it works !

Thanks. worked for me!

Mohsents commented 3 years ago

I faced to this similar issue: I was trying to retain a dialog while configuration change, and I got this error. Well, I just dismiss() the dialog in the onStop() method and I got no more errors.

jaredh159 commented 1 year ago

I have no idea if this is right, or if it will help someone else, but I was struggling with this for hours, and ultimately what seemed to fix it for me was adding the onPause java func shown above combined with removing the javascript call to SplashScreen.hide(). the splash screen still got out of the way (i have no idea why/how) and the crash stopped. i was testing on an old kindle fire, fwiw. ¯\(ツ)