我想在加载资源时将动画图像(当前使用一组 PNG)显示为启动画面。
我已经能够使用这个来显示启动画面。但问题是:启动画面显示指定时间然后黑屏 2-3 秒然后index.html
被加载。
理想情况下,我想要的是在加载资源时显示启动画面。加载资源后,拉动闪屏并立即加载index.html
文件。
下面是我的代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Splash screen view
setContentView(R.layout.splash);
// Start animating the image
final ImageView splashImageView = (ImageView) findViewById(R.id.SplashImageView);
splashImageView.setBackgroundResource(R.drawable.flag);
final AnimationDrawable frameAnimation = (AnimationDrawable)splashImageView.getBackground();
splashImageView.post(new Runnable(){
@Override
public void run() {
frameAnimation.start();
}
});
final SplashScreen sPlashScreen = this;
// The thread to wait for splash screen events
mSplashThread = new Thread(){
@Override
public void run(){
try {
synchronized(this){
// Wait given period of time or exit on touch
wait(10000);
}
}
catch(InterruptedException ex){
}
finish();
// Run next activity
Intent intent = new Intent();
intent.setClass(sPlashScreen, SomeActivity.class);
startActivity(intent);
//stop();
}
};
mSplashThread.start();
}
public class SomeActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
//some code to copy database files.
}
}
请注意我的开发环境。android-sdk:API 级别 17,Phonegap:2.1.0。