2016-04-16 121 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> 
相关问题