簡體   English   中英

Cordova (Ionic) : Splashscreen 在 Android 上只能工作一次

[英]Cordova (Ionic) : Splashscreen only works one time on Android

我使用 Cordova 插件創建了一個 Splashscreen,方法是將插件添加到我的 Ionic 應用程序中:

cordova plugin add org.apache.cordova.splashscreen

當我在我的 Android 手機上安裝該應用程序並首次運行它時,我看到啟動畫面正在工作。 但是如果我按后退按鈕退出應用程序然后重新打開應用程序,這次我看不到啟動畫面,它直接進入主屏幕。 我認為這是因為當我按下后退按鈕時,應用程序沒有完全關閉(退出)。 因此,如果我轉到仍在運行的應用程序列表並手動關閉我的應用程序(從正在運行的應用程序列表中),那么下次我打開我的應用程序時,我會再次看到啟動畫面。

我嘗試在按下后退按鈕時退出應用程序:

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, true);
}

function onDeviceReady() {
    document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown()
{
 navigator.app.exitApp();
}

在我的 JavaScript 代碼中,但它沒有幫助。 對此有什么好的解決方案?

Splashscreen 用於在加載應用程序時顯示默認圖像,我們不希望用戶在應用程序啟動時因黑屏而感到沮喪。 因此,android 在coldstart啟動時顯示啟動畫面(應用程序在被殺死時正在啟動)。 你通常並不需要顯示在閃屏hotstart ,但如果這樣做,你可以使用下面通過濺射屏幕科爾多瓦插件暴露JavaScript方法:

navigator.splashscreen.show();
navigator.splashscreen.hide();

只要確保在platform ready時調用它們ready 或者,您可以使用ngCordova為您提供可注入的服務 api: http : ngCordova

處理恢復事件:

document.addEventListener('deviceready', function () {
  document.addEventListener('resume', yourAsyncResumeCallback, false);
});

你的應用程序的行為很奇怪。 即使在后退按鈕並重新打開后,我的應用程序也會再次顯示啟動畫面。 這是我的config.xml如果您不希望棄用版本從下面的標簽中刪除 'gap:' 並在version="1.0.0"重命名版本,它可以與閃屏一起使用

<?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns="http://www.w3.org/ns/widgets"
        xmlns:gap="http://phonegap.com/ns/1.0"
        id="testaplikacji"
        versionCode="1"
        version="1.0.0">

        <name>Your app name</name>
        <description>Desc</description>
        <author>Author</author>
        <gap:platform name="android">
        </gap:platform>
        <preference name="SplashScreen" value="splash" />
        <preference name="SplashScreenDelay" value="5000" />
        <gap:plugin name="org.apache.cordova.splashscreen" spec="1.0.0" source="pgb" />         
        <gap:splash src="splash.png" gap:platform="android" gap:qualifier="ldpi" width="500" height="500" /> 
        <gap:splash src="splash.png" />

    </widget>

, splash.png http://imgur.com/jmfxR4tindex.html當然資產(jqmobile1.4.2.css 和 .js 和 jquery1.11.3)本地作為我的 '.\\' 或 http:... 鏈接

<html>
    <head>
        <meta charset="UTF-8">
        <link href=".\jquery.mobile-1.4.2.css" rel="stylesheet" type="text/css" />
        <script src=".\jquery-1.11.3.js"></script>
        <script src=".\jquery.mobile-1.4.2.js"></script>

        <script type="text/javascript" charset="utf-8" src="cordova.js"></script>

        <script type="text/javascript" charset="utf-8">

        function init() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }

        function onDeviceReady() {
          //do stuff
        }

        </script>
    </head>

    <body onload="init()">

    </body>
</html>

暫無
暫無

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

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