检查活动是否有效

时间:2016-01-02 18:44:44

标签: android

当来电或应用程序最小化时 - 触发run()。这不应该是

final View activityRootView = findViewById(R.id.webView);
        activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            private int lastHeight;
            @Override
            public void onGlobalLayout() {
                if (lastHeight == 0) {
                    lastHeight = activityRootView.getHeight();
                }
  if (lastHeight < activityRootView.getHeight() && activityRootView.getHeight() - lastHeight > 100 && **current activity active**) {
                    WebView vw = (WebView) findViewById(R.id.webView);
                    vw.loadUrl("javascript:run()");
                }
                lastHeight = activityRootView.getHeight(); 
            }
        });

0 个答案:

没有答案