2016-04-16 120 views
2

我已經通過添加插件來我離子的應用程序創建爲使用科爾多瓦插件一個閃屏:科爾多瓦(離子):閃屏只能一次在Android

cordova plugin add org.apache.cordova.splashscreen 

當我在我的Android手機上安裝應用程序並第一次運行它,我看到啓動畫面工作。但是如果我按下後退按鈕退出應用程序,然後重新打開應用程序,這次我沒有看到啓動畫面,它直接進入主屏幕。我認爲這是由於我按下後退按鈕時應用程序未完全關閉(退出)。因此,如果我進入仍在運行的應用程序列表並手動關閉我的應用程序(從正在運行的應用程序列表中),那麼下次打開我的應用程序時,我會再次看到splashscreen。

我想退出應用程序時使用按後退按鈕:

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

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

在我的JavaScript代碼,但它並沒有幫助。 什麼是這個好的解決方案?

回答

1

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

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

只要確保你把這些當platformready。另外,您也可以使用ngCordova爲您提供一種可注射的服務API此:http://ngcordova.com/docs/plugins/splashscreen/

手柄恢復事件:

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

感謝您的回答。我嘗試添加:'navigator.splashscreen.show();''onDeviceReady()''函數內部,但它仍然不起作用,你知道爲什麼嗎? – TJ1

+0

在你的情況下,該設備是從後臺帶來的。因此,您可以使用cordova事件生命週期事件「resume」,該事件被稱爲該精確場景。請參閱:https://cordova.apache.org/docs/en/4.0.0/cordova/events/events.resume.html。如果您的問題已解決,請同意接受:) –

+0

您能否將完整的解決方案放在答案中。我嘗試了在onResumeMyApp函數中添加'navigator.splashscreen.show();'的方法,並添加了這個'document.addEventListener(「resume」,onResumeMyApp,false);'。但仍然沒有工作。 – TJ1

0

您的應用程序的行爲是怪異。我的應用程序甚至在後退和重新打開後再次顯示splashscreen。這裏是我的config.xml中,如果你不想棄用版本刪除與閃屏的工作原理「的差距:」從下面的標籤,並在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.pnghttp://imgur.com/jmfxR4t指數重命名版本。當然資產(jqmobile1.4.2.css和.js和jquery1.11.3)當地礦山 '\' 或HTTP的HTML:...鏈接

<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> 
相關問題