简体   繁体   English

Android应用重新打开后显示白屏

[英]Android app shows white screen after reopening

I have created a very simple app that opens website in phone browser, this is the only code that allows me to open pdf files and sends contacts page correctly, all works perfectly fine apart from one thing, after the app opens and displays web page, if you press back button it displays a white page layout with heading, and you have to press again to exit or if you press home button and go back into app it displays white page again. 我创建了一个非常简单的应用程序,可以在手机浏览器中打开网站,这是唯一允许我打开pdf文件并正确发送联系人页面的代码,在打开并显示网页后,除了一件事情之外,其他所有功能都可以正常运行,如果您按下返回按钮,它将显示带有标题的白页布局,您必须再次按下以退出,或者如果您按下主页按钮并返回应用程序,它将再次显示白页。 i am obviously missing something could anyone please show me how to fix. 我显然缺少任何人都可以向我展示如何解决。

MainActivity.java 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 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"

Manifest 表现

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

I'm not sure if you realised that your app doesn't load the webpage itself. 我不确定您是否意识到自己的应用程序不会加载网页本身。 Your MainActivity just constructs an implicit Intent and passes it to the System. 您的MainActivity只是构造一个隐式Intent并将其传递给System。 If you have a default browser set, you won't get prompted and it will open your default browser directly. 如果您设置了默认浏览器,则不会提示您,它将直接打开默认浏览器。 For that matter, your activity_main.xml could be an empty FrameLayout and doesn't have to be a WebView. 因此,您的activity_main.xml可以是一个空的FrameLayout,而不必是WebView。

With that out of the way, if the intention of your app is simply redirecting to a certain web page (like a bookmark), then the white page that you see is your MainActivity, it usually remains in the backstack after redirecting. 这样一来,如果应用程序的意图只是重定向到某个网页(如书签),那么您看到的白页就是您的MainActivity,它通常在重定向后仍留在后台。 That's why pressing back, or choosing your app from the app switcher will show the white page (which is your MainActivity). 因此,按回去或从应用程序切换器中选择您的应用程序将显示白页(这是您的MainActivity)。

Excluding it from the history/backstack might possibly fix the issue (haven't tried it though), give it a shot: 从历史记录/堆栈中排除它可能可以解决该问题(尽管没有尝试过),请试一下:

Manifest: 表现:

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

let me know if it worked. 让我知道是否有效。

When you are tapping back, MainActivity of your application is being displayed. 当您点击时,将显示您的应用程序的MainActivity。 After Starting browser activity, finish the current Activity. 启动浏览器活动后,完成当前活动。 In onCreate method on 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

This white screen issue may occur on app launch as well. 此白屏问题也可能在应用启动时发生。 To fix it, set transparent, full-screen theme to MainActivity. 要解决此问题,请将透明的全屏主题设置为MainActivity。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM