我怎么可以加载2活动,展现了第一和一汽秒后第二个? [英] how can i load 2 activities, show the first and after faw seconds the second?
本文介绍了我怎么可以加载2活动,展现了第一和一汽秒后第二个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想加载网站(web视图),但它加载速度太慢,并显示一个白色的屏幕。我想显示启动画面,并在后台加载的WebView。几秒钟后,我想关闭闪屏并表明应由然后准备现场。我该怎么办呢?
谢谢!
I want to load a website (in WebView), but it loads too slow and show a white screen. I want to show a splash screen and in the background load the WebView. After few seconds I want to close the splash screen and show the site that should be ready by then. How can I do it? Thanks!
推荐答案
您可以使用以下code吧。
You can use the following code for it.
public class Splash extends Activity {
/** Called when the activity is first created. */
private boolean mSplashActive = true, mPaused;
private long mSplashTime = 1000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new Thread(){
public void run(){
try {
long ms = 0;
while(mSplashActive && ms < mSplashTime) {
sleep(100);
if(!mPaused) {
ms += 100;
}
}
if(Resources.getResources().isUserRegistered(Splash.this)) {
//user is registered so launch main screen
} else {
//user is not registered launch welcome wizard.
Intent intent = new Intent(Splash.this, WelcomeScreen.class);
Splash.this.startActivity(intent);
}
finish();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
@Override
public void onPause(){
super.onPause();
mPaused = true;
}
@Override
public void onResume(){
super.onResume();
mPaused = false;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyDown(keyCode, event);
if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
mSplashActive = false;
}
return true;
}
}
这篇关于我怎么可以加载2活动,展现了第一和一汽秒后第二个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文