java - 泄露的窗口 com.android.internal.policy.impl

标签 java android memory-leaks splash-screen

我正在尝试解决突然弹出的日志异常。 我以前从未见过它,但是,我大约有 5 周没有运行这个应用程序,所以也许它是由于任何更新或其他原因而产生的新内容。 这是我的类(class)代码:

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 1000;
    private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
    private static final String TAG = "SplashPush";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);

        new Handler().postDelayed(new Runnable() {

            /*
             * Showing the splash screen for the selected time
             */
            @Override
            public void run() {
                // Once the timer is over we will start the main activity
                Intent i = new Intent(SplashScreen.this, ClientDriverMainScreen.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);

        if (checkPlayServices()) {
            Intent i = new Intent(this, RegistrationIntentService.class);
            startService(i);
        }
    }

        /**
         * Check the device to make sure it has the Google Play Services APK. If
         * it doesn't, display a dialog that allows users to download the APK from
         * the Google Play Store or enable it in the device's system settings.
         */
    private boolean checkPlayServices() {
        GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
        int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.SUCCESS) {
            if (apiAvailability.isUserResolvableError(resultCode)) {
                apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                        .show();
            } else {
                Log.i(TAG, "This device is not supported.");
                finish();
            }
            return false;
        }
        return true;
    }
}

但我不断遇到异常:

Activity activiteslogic.splash.SplashScreen has leaked window.

有人有线索或提示要寻找什么吗?

完整的 Logcat:

08-22 12:41:03.609 1849-1849/zooz.ivmobs.com.zooz E/WindowManager: android.view.WindowLeaked: Activity activiteslogic.splash.SplashScreen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{52860efc V.E..... R......D 0,0-1026,639} that was originally added here
                                                                   at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
                                                                   at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
                                                                   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
                                                                   at android.app.Dialog.show(Dialog.java:286)
                                                                   at activiteslogic.splash.SplashScreen.checkPlayServices(SplashScreen.java:65)
                                                                   at activiteslogic.splash.SplashScreen.onCreate(SplashScreen.java:48)
                                                                   at android.app.Activity.performCreate(Activity.java:5231)
                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
                                                                   at android.app.ActivityThread.access$800(ActivityThread.java:135)
                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                   at android.os.Looper.loop(Looper.java:136)
                                                                   at android.app.ActivityThread.main(ActivityThread.java:5001)
                                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                                                                   at dalvik.system.NativeStart.main(Native Method)

最佳答案

用于将上下文 this 更改为 youractivity.this

    if (checkPlayServices()) {
        Intent i = new Intent(SplashScreen.this, RegistrationIntentService.class);
        startService(i);
    }




private boolean checkPlayServices() {
    GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
    int resultCode = apiAvailability.isGooglePlayServicesAvailable(SplashScreen.this);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (apiAvailability.isUserResolvableError(resultCode)) {
            apiAvailability.getErrorDialog(SplashScreen.this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
                    .show();
        } else {
            Log.i(TAG, "This device is not supported.");
            finish();
        }
        return false;
    }
    return true;
}

关于java - 泄露的窗口 com.android.internal.policy.impl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39080077/

相关文章:

java - Spring @Transactional 跨越两个 Hibernate 事务管理器的一个服务方法

java - 在java中使用基于屏幕的soap api调用Acumatica报告

Java 类型捕获集合中的通配符

android - 如何在 Android 中更改菜单主题

Python:内存泄漏调试

java - 为什么 Java Streams 是一次性的?

javascript - 在 Chromecast 上切换音轨

java - map 就绪回调返回 null

c - 如何避免这段代码中的内存泄漏?

c++ - 如果将 delete[] 应用于非数组指针会发生什么?