【问题标题】:fatal signal 11 (SIGSEVG) in my WebView我的 WebView 中的致命信号 11 (SIGSEVG)
【发布时间】:2014-03-21 18:01:20
【问题描述】:

我遇到的问题是,有时当我在我的应用程序中打开 webView Activity 时,它工作正常,有时会出现致命信号 11 并且应用程序关闭

这是我的 webView 类

public class Browser extends Activity{

WebView ourBrow;
String adress;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browser);
    try{            
        try{
            getActionBar().setDisplayShowHomeEnabled(false);
        }
        catch (Exception e)
        { }

        ourBrow = (WebView)findViewById(R.id.wvBrowser);

        ourBrow.getSettings().setJavaScriptEnabled(true); 
        ourBrow.getSettings().setLoadWithOverviewMode(true); 
        ourBrow.getSettings().setUseWideViewPort(true);  
        ourBrow.setWebViewClient(new ourViewClient());  
        ourBrow.setWebChromeClient(new WebChromeClient());
        ourBrow.getSettings().setSupportMultipleWindows(true);

        try{
            Bundle gotBasket = getIntent().getExtras();
            adress = gotBasket.getString("url");
        }catch (Exception e){

        }

        try
        {
            ourBrow.loadUrl(adress);
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }

    }catch(Exception e)
    {

    }

}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourBrow.stopLoading();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_goback, menu);

    return true;

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
    // action when setting was selected
    case R.id.goback:
      finish();
      break;

    default:
      break;
    }

    return true;
}

public class ourViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub
        view.loadUrl(url);
        return true;
    }

}


public void clickEvent_live (View view)
{
    if (!adress.contains("live"))
    {
        Intent intent_live = new Intent(this,Browser.class);
        intent_live.putExtra("url", CommonUtilities.LIVE_URL);
        startActivity(intent_live);
    }
}

}

这是日志

这些警告也会出现

谢谢

【问题讨论】:

标签: android webview


【解决方案1】:

我相信您的问题在于您的活动的onPause。首先,当您关闭 Activity 时,您应该销毁您的 WebView 以确保它不会在内存中徘徊(在播放视频的情况下,它将继续在后台播放。

如果 WebView 是否为空,您需要检查 onPause,因为不知何故,三星设备并不总是正确地销毁对象......我只遇到了三星设备的奇怪问题。

你的 onPause 应该如下:

@Override
protected void onPause() {
    super.onPause();
    if(ourBrow != null) {
        ourBrow.stopLoading();
        ourBrow.onPause(); //pauses background threads, stops playing sound
        ourBrow.pauseTimers(); //pauses the WebViewCore
    }
}

并且你的 onOptionsItemSelected 应该如下(为了正确销毁 WebView):

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.goback:
      ourBrow.stopLoading();
      ourBrow.onPause(); //pauses background threads, stops playing sound
      ourBrow.pauseTimers(); //pauses the WebViewCore
      ourBrow.destroyDrawingCache(); //removes the view from RAM
      ourBrow = null; //you need to nullify the WebView because due to the odd way that the Activity lifecyle works, sometimes onPause is called when you start up your activity
      finish();
      break;

    default:
      break;
    }

    return true;
}

编辑:所以我只记得我在三星设备上遇到的具体问题是,有时尝试加载 null 或空 url 会导致应用程序崩溃,并使用 SIGSEGV 而不是抛出空指针异常。尝试将您的 onCreate 更改为:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.browser);
    try{            
        try{
            getActionBar().setDisplayShowHomeEnabled(false);
        }
        catch (Exception e)
        { }

        ourBrow = (WebView)findViewById(R.id.wvBrowser);

        ourBrow.getSettings().setJavaScriptEnabled(true); 
        ourBrow.getSettings().setLoadWithOverviewMode(true); 
        ourBrow.getSettings().setUseWideViewPort(true);  
        ourBrow.setWebViewClient(new ourViewClient());  
        ourBrow.setWebChromeClient(new WebChromeClient());
        ourBrow.getSettings().setSupportMultipleWindows(true);

        String url = null;
        Intent intent = getIntent();
        if(intent != null) {
            if(intent.getExtras() != null) {
                url = intent.getExtras().getString("url");
            }
        }

        if(url != null && !url.equals("")) {
            ourBrow.loadUrl(url);
        }


    } catch(Exception e) {

    }

}

我不完全确定这是否可行,但它帮助我修复了一个错误。

【讨论】:

  • 我测试了你的代码,但还是有同样的问题
  • 好的,我很确定我明白了问题所在。给我一分钟更新我的答案。
  • 太棒了!您能否将答案标记为正确,以便其他人知道它解决了问题?
【解决方案2】:

除非您编写了自己的 NDK 代码,否则作为 Java 开发人员,您无能为力,会导致 SIGSEGV

在运行相同 API 级别的模拟器中尝试您的项目。如果那里也出现问题,那么问题肯定出在 Android 上,您可能希望 file an issue 提供示例项目和重现崩溃的说明。否则,您可能需要contact Samsung 并向他们提供示例项目和说明。

【讨论】:

  • 我以前在使用 WebView 时遇到过段错误,总是在三星设备上,从不在其他设备上。他们对 WebView 做了一些事情,导致它偶尔在 Android 上崩溃。
  • @A.C.R.Development:更有理由为他们提供示例项目和重现段错误的步骤。
【解决方案3】:

这个解决方案

mWebView = new WebView(getApplicationContext());
mMainView.addView(mWebView);

@Override
protected void onPause() {
    super.onPause();
    if (mWebView != null) {
        mWebView.stopLoading();
        mWebView.onPause();
        mWebView.pauseTimers();

    }
}

@Override
public void finish() {
    super.finish();
    if (mWebView != null) {
        mWebView.removeAllViews();
        mMainView.removeView(mWebView);
        mWebView.setTag(null);
        mWebView.clearCache(true);
        mWebView.destroyDrawingCache();
        mWebView.destroy();
        mWebView=null;
    }
}

【讨论】:

    【解决方案4】:

    我遇到了类似的问题,您的研究确实帮助我了解了它的来源。 对我来说,将 Web 视图渲染优先级设置为低就足够了

    webView.getSettings().setRenderPriority(RenderPriority.LOW);
    

    我只能推测是什么原因造成的,但似乎 JavaScript 动画的内容对于 UI 线程的其余部分来说花费了太长时间。 遗憾的是,您无法将 Web 视图与 UI 线程分离。

    我希望我的“解决方法”能在短时间内有所帮助,但这肯定不是解决方案。

    【讨论】:

      猜你喜欢
      • 2012-09-16
      • 1970-01-01
      • 2012-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多