簡體   English   中英

Android應用重新打開后顯示白屏

[英]Android app shows white screen after reopening

我創建了一個非常簡單的應用程序,可以在手機瀏覽器中打開網站,這是唯一允許我打開pdf文件並正確發送聯系人頁面的代碼,在打開並顯示網頁后,除了一件事情之外,其他所有功能都可以正常運行,如果您按下返回按鈕,它將顯示帶有標題的白頁布局,您必須再次按下以退出,或者如果您按下主頁按鈕並返回應用程序,它將再次顯示白頁。 我顯然缺少任何人都可以向我展示如何解決。

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Uri uriUrl = Uri.parse("http://www.ribs2go.com.au");
    Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
    startActivity(launchBrowser);

}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

表現

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

我不確定您是否意識到自己的應用程序不會加載網頁本身。 您的MainActivity只是構造一個隱式Intent並將其傳遞給System。 如果您設置了默認瀏覽器,則不會提示您,它將直接打開默認瀏覽器。 因此,您的activity_main.xml可以是一個空的FrameLayout,而不必是WebView。

這樣一來,如果應用程序的意圖只是重定向到某個網頁(如書簽),那么您看到的白頁就是您的MainActivity,它通常在重定向后仍留在后台。 因此,按回去或從應用程序切換器中選擇您的應用程序將顯示白頁(這是您的MainActivity)。

從歷史記錄/堆棧中排除它可能可以解決該問題(盡管沒有嘗試過),請試一下:

表現:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:noHistory="true"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

讓我知道是否有效。

當您點擊時,將顯示您的應用程序的MainActivity。 啟動瀏覽器活動后,完成當前活動。 在MainActivity的onCreate方法中,

...

Uri uriUrl = Uri.parse("http://www.ribs2go.com.au");
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
finish(); // This is the fix, finish MainActivity

此白屏問題也可能在應用啟動時發生。 要解決此問題,請將透明的全屏主題設置為MainActivity。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM