2013-08-29 10 views
10

Mam aktywność wyświetlającą strony internetowe. W niektórych telefonach (np. Huawei Ascend) działanie to ulega awarii w sposób, który powoduje ponowne uruchomienie aplikacji, ale nie powoduje zwykłego wyskakującego okienka błędu dla Androida. (Inne telefony (np. Nexus) nigdy się nie zawieszają.) Wygląda na to, że zawsze się zawiesza podczas ładowania strony internetowej, ale nie w żadnym konkretnym punkcie, np. czasami w shoulOverrideUrlLoading, czasami podczas onPageStarted lub onPageFinished.WebView powoduje restart aplikacji - sygnał krytyczny 11 (SIGSEGV)

myślę WebView powoduje this--

08-29 21: 08: 22,577: A/libc (957): 11 (sygnał krytyczny SIGSEGV) w 0x00000008 (kod = 1), gwint 957

- ale nie mogę zrozumieć dlaczego.

Oto aktywność:

public class WebDisplay extends Activity 
{ 

    private String sentUrl = ""; 
    public WebView myWebView; 
    public ProgressBar spinner; 

    @SuppressLint("SetJavaScriptEnabled") 
    @Override 
    protected void onCreate (Bundle savedInstanceState) 
    { 
    super.onCreate(savedInstanceState); 
    Log.d("WEBVIEW", "onCreate"); 
    getWindow().setBackgroundDrawableResource(R.color.white); 

    Bundle extras = getIntent().getExtras(); 
    if (null != extras) 
    { 
     sentUrl = extras.getString("displayURL"); 
    } 

    setContentView(R.layout.webdisplay); 

    myWebView = (WebView) findViewById(R.id.webDisplay); 
    spinner = (ProgressBar) findViewById(R.id.webLoading); 

    // WebView displays default to showing things in exact pixel size at 100% 
    // resolution, meaning it generally opens on a zoomed in portion of the 
    // top left of the web page and refuses to let you zoom out, so we have 
    // to force it to display pages a bit more reasonably. 
    myWebView.getSettings().setLoadWithOverviewMode(true); 
    myWebView.getSettings().setUseWideViewPort(true); 
    myWebView.getSettings().setPluginState(WebSettings.PluginState.ON); 

    // By default, there is no javascript support or zoom controls, so 
    // turn both of those on. 
    WebSettings webSettings = myWebView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    webSettings.setSupportZoom(true); 
    webSettings.setBuiltInZoomControls(true); 
    webSettings.setJavaScriptCanOpenWindowsAutomatically(true); 

    // We want links to continue opening inside the app. 
    myWebView.setWebViewClient(new WebViewClient() { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      Log.d("WEBVIEW", "loadUrl="+url); 
      view.loadUrl(url); // open link in the same web view.   
      return true; 
     } 

     @Override 
     public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) { 
     Log.d("WEBVIEW", "onPageStarted="+url); 
     super.onPageStarted(view, url, favicon); 
     if (View.GONE == spinner.getVisibility()) { spinner.setVisibility(View.VISIBLE); } 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
     Log.d("WEBVIEW", "onPageFinished="+url); 
     super.onPageFinished(view, url); 
     if (View.VISIBLE == spinner.getVisibility()) { spinner.setVisibility(View.GONE); } 
     } 

     @Override 
     public void onReceivedError(WebView view, int errorCode, String description, String url) { 
     Log.d("WEBVIEW", "onPageError="+url+"::descr="+description); 
     } 

    }); 

    // Try to get YouTube videos working. 
    myWebView.setWebChromeClient(new WebChromeClient() { 
    }); 

    // So the user doesn't have to back through their entire history to get 
    // back to the app, we provide a "done browsing" button. 
    Button doneButton = (Button) findViewById(R.id.doneButton); 
    doneButton.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View v) 
     { 
     finish(); 
     } 
    }); 

    ImageButton backButton = (ImageButton) findViewById(R.id.webBackButton); 
    backButton.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View arg0) 
     { 
     myWebView.goBack(); 
     }  
    }); 

    ImageButton fwdButton = (ImageButton) findViewById(R.id.webForwardButton); 
    fwdButton.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View arg0) 
     { 
     myWebView.goForward(); 
     }  
    }); 

    ImageButton refreshButton = (ImageButton) findViewById(R.id.refreshButton); 
    refreshButton.setOnClickListener(new OnClickListener(){ 
     @Override 
     public void onClick(View arg0) 
     { 
     myWebView.reload(); 
     }  
    }); 

    myWebView.loadUrl(sentUrl); 
    } 

    @Override 
    protected void onSaveInstanceState(Bundle outState) 
    { 
    super.onSaveInstanceState(outState); 

    // Save the state of the WebView 
    myWebView.saveState(outState); 
    } 

    @Override 
    protected void onRestoreInstanceState(Bundle savedInstanceState) 
    { 
    super.onRestoreInstanceState(savedInstanceState); 

    // Restore the state of the WebView 
    myWebView.restoreState(savedInstanceState); 
    } 
} 

A oto załadowany układ:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white" > 


    <RelativeLayout 
     android:id="@+id/webNavBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/abs__background_holo_light" 
     android:layout_alignParentBottom="true" 
     android:padding="2dp" > 

    <Button 
     android:id="@+id/doneButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/refreshButton" 
     android:layout_alignTop="@+id/refreshButton" 
     android:background="@drawable/custom_button" 
     android:padding="5dp" 
     android:text="@string/web_done" 
     android:textColor="@color/white" 
     android:textStyle="bold" /> 

    <ImageButton 
     android:id="@+id/refreshButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/custom_button" 
     android:src="@drawable/ic_action_refresh" 
     android:contentDescription="@string/web_refresh" 
     android:textColor="@color/white" 
     android:padding="5dp" /> 

    <ImageButton 
     android:id="@+id/webBackButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="5dp" 
     android:layout_toLeftOf="@+id/webForwardButton" 
     android:background="@drawable/custom_button" 
     android:src="@drawable/navigation_back" 
     android:padding="5dp" 
     android:contentDescription="@string/web_back" 
     android:textColor="@color/white" /> 

    <ImageButton 
     android:id="@+id/webForwardButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/custom_button" 
     android:src="@drawable/navigation_forward" 
     android:contentDescription="@string/web_forward" 
     android:textColor="@color/white" 
     android:padding="5dp" /> 



    </RelativeLayout> 

    <WebView 
     android:id="@+id/webDisplay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentTop="true" 
     android:layout_above="@id/webNavBar" /> 

    <ProgressBar 
     android:id="@+id/webLoading" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="80dp" 
     style="@android:style/Widget.ProgressBar.Large"   
     android:layout_centerHorizontal="true" /> 

</RelativeLayout> 

ETA: Włączanie akceleracji sprzętowej off jak to

myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); 

wydaje się zatrzymać SIGSEV, ale także zatrzymuje Yo Odtwarzanie filmów w YouTube (wciąż mam audio, ale nie ma obrazu).

+0

Widziałeś te? http://stackoverflow.com/questions/14023291/fatal-signal-11-sigsegv-at-0x00000000-code-1-phonegap http://stackoverflow.com/questions/10662446/invalid-heap-address-and -fatal-signal-11 –

+3

@JasonCrosby - tak; Niestety, "jest to błąd w oprogramowaniu urządzenia" odpowiedź wydaje się być najbardziej prawdopodobna (i jednocześnie najmniej pomocna, jeśli chodzi o faktyczne zapobieganie błędowi, do cholery, producenci urządzeń z systemem Android!) –

+0

Lol yea jej zawsze frustrujące, gdy pojawia się błąd i nie można wiele z tym zrobić. –

Odpowiedz

3

upewnij się, że WebView jest pierwszym elementem RelativeLayout. lub nie używaj RelativeLayout, po prostu spróbuj LinearLayout. lub usunąć atrybuty android: layout_alignParentTop = "true" android: layout_above = "@ id/webNavBar" z WebView

+7

Jaki jest tego powód? – Jaec

0
webSettings.setJavaScriptEnabled(true); 

Ustawienia powyżej powoduje "Fatal signal 11 (SIGSEGV)" błąd na niektórych stronach z wykorzystaniem skryptu Java. Powieliłem ten błąd na karcie Samsung Galaxy Tab 3 i Galaxy 3 lite. Wersja Androida 4.4.2 dla obu urządzeń.

Jeśli usunę funkcję "setJavaScriptEnabled", działa poprawnie.

Powiązane problemy