Android的闪屏"申请表]类 [英] Android Splash screen for "Application" class
问题描述
我有一个Android应用程序在那里我已经扩展了基础应用类,以设置一些全局变量。
I have an Android app where I've extended the base Application class in order to set up some global variables.
public class MyApplication extends Application {
private ArrayList<ModelClass> master_list; // global variable 1
private DataBaseHelper db_helper; // global variable 2
@Override
public void onCreate() {
super.onCreate();
//do database work that will take about 5 seconds
}
}
我想显示启动画面给用户的应用程序类工作时(即我的主要活动是创建之前)。有没有办法做到这一点?
I'd like to show a splash screen to the user while the Application class is working (i.e. before my Main Activity is created). Is there a way to do this?
推荐答案
您可以使SplashActivity你的启动活动。
You could make the SplashActivity your start activity.
在所有MyApplication已经完成它的工作,你就可以开始你的主要活动和处置的启动画面。
When MyApplication has completed it's work you could start your main activity and dispose the splash screen.
但不要做的onCreate繁重的数据库工作,创建另一个功能,做到有,否则你溅活动将不被显示。
But don't do the heavy database work in onCreate, create another function and do it there, otherwise your splash activity won't be shown.
public class SplashActivity extends Activity
@override
protected void onResume() {
//Create a thread
new Thread(new Runnable() {
public void run() {
//Do heavy work in background
((MyApplication)getApplication()).loadFromDb();
startActivity(new Intent(SplashActivity.this, MainActivity.class));
finish(); //End this activity
}
}).start();
}
}
这篇关于Android的闪屏&QUOT;申请表]类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!