我的应用程序有一个带有动画徽标的初始屏幕(使用线程),然后显示一个菜单页面。
现在我想在我的闪屏中做一些后台活动。那就是我想将一些图像转换为字符串等。
我已将执行此操作的代码放在我的 onCreate() 函数中。但问题是,我看到的不是启动画面,而是一个空白的白屏,然后是一个黑屏。然后过一段时间菜单页面照常显示。
如果我评论后台处理的代码,它会完美运行。后台代码也正常工作。只是他们不能一起正常工作。logcat 中没有错误,我不知道出了什么问题。
闪屏的Java代码
public class Splash extends Activity {
protected int _splashTime = 10000;
private Thread splashTread;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//MakeFolder();
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splash);
MakeFolder();
ImageView IM =(ImageView)findViewById(R.id.imageView2);
final Animation mobianim = AnimationUtils.loadAnimation(this, R.anim.mobianim);
IM.setAnimation(mobianim);
mobianim.setDuration(1000);
animate();
// AnimateLogo();
final Splash sPlashScreen = this;
// thread for displaying the SplashScreen
splashTread = new Thread() {
@Override
public void run() {
try {
synchronized(this){
wait(_splashTime);
}
} catch(InterruptedException e) {}
finally {
finish();
Intent i = new Intent();
i.setClass(sPlashScreen, MenuPg.class);
startActivity(i);
// stop();
}
}
};
splashTread.start();
/*
**Code for doing background things**
*/
}
public void MakeFolder(){
File direct = new File(Environment.getExternalStorageDirectory() + "/MyFolder");
if(!direct.exists())
{
if(direct.mkdir()){ //directory is created;
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
synchronized(splashTread){
splashTread.notifyAll();
}
}
return true;
}
public void animate(){
ImageView IV1=(ImageView)findViewById(R.id.imageView1);
AlphaAnimation alphaAmin = new AlphaAnimation(0,1);
IV1.setAnimation(alphaAmin);
alphaAmin.setDuration(5000);
}
}