wael
wael

Reputation: 454

fatal signal 11 (SIGSEVG) in my WebView

The problem i have is that sometimes when i open a webView Activity in my apps it works fine and sometimes a fatal signal 11 occures and the apps shut down

this is my webView Class

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);
    }
}

}

and this is the log

enter image description here

and these warnings comes up too

enter image description here

thx

Upvotes: 2

Views: 4581

Answers (4)

kingway
kingway

Reputation: 21

This solution

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;
    }
}

Upvotes: 0

Semo
Semo

Reputation: 111

I encountered a similar problem and your research really helped me to understand where this comes from. For me it was enough to set the web view render priority to low

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

I can only speculate what causes this but it seams like the JavaScript animation stuff took too long for the rest of the UI thread. Sadly you can't uncouple the web view from the UI thread.

I hope my "workaround" helps for a short time but it is for sure not a solution.

Upvotes: -1

anthonycr
anthonycr

Reputation: 4186

I believe that your issue is on the onPause of your activity. First of all, when you close your activity, you should destroy your WebView to ensure that it's not hanging around in memory (in the case of a video playing, it will keep playing in the background.

You need to check in onPause if the WebView is null or not, because somehow Samsung devices don't always destroy objects correctly... I've run into weird issues with only Samsung devices.

Your onPause should be as follows:

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

And your onOptionsItemSelected should be as follows (in order to properly destroy the 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;
}

Edit: So I just remembered the specific issue I had with Samsung devices was that sometimes trying to load a null or empty url would crash the app with a SIGSEGV instead of throwing a null pointer exception. Try changing your onCreate to this:

@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) {

    }

}

I'm not entirely sure if this will work, but it's what helped me fix an error.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007533

Unless you have written your own NDK code, there is nothing that you can do as a Java developer that should result in a SIGSEGV.

Try your project in an emulator running the same API level. If the problem occurs there too, then the issue is definitely with Android, and you might want to file an issue with a sample project and instructions to reproduce the crash. Otherwise, you might want to contact Samsung and provide them with the sample project and instructions.

Upvotes: 0

Related Questions