我的SplashScreenActivity存在问题,当我在手机上启动应用程序时,它显示白屏大约0.5秒. MainActitivy扩展了FragmentActivity,在AndroidManifest中,我将SplashScreenActivity声明为启动器和纵向模式作为screenorIEntation.
代码:
public class SplashScreenActivity extends Activity {@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestwindowFeature(Window.FEATURE_NO_Title); setContentVIEw(R.layout.splashscreen); randomSplash(); Thread splashscreen = new Thread() { public voID run() { try { Thread.sleep(1000); Intent mainScreen = new Intent("com.rm.jkrm.MAINACTIVITY"); startActivity(mainScreen); } catch (InterruptedException e) { } finally { finish(); } } }; splashscreen.start();}private voID randomSplash(){ Random random = new Random(); int i = random.nextInt(4); linearLayout ln = (linearLayout) findVIEwByID(R.ID.splashscreen); switch(i){ case 1: ln.setBackgroundResource(R.drawable.splash1); break; case 2: ln.setBackgroundResource(R.drawable.splash2); break; case 3: ln.setBackgroundResource(R.drawable.splash3); break; default: ln.setBackgroundResource(R.drawable.splash0); break; }}}
XML:
<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/splashscreen" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical"></linearLayout>
解决方法:
Thread splashscreen = new Thread() { public voID run() { try { Thread.sleep(1000); Intent mainScreen = new Intent("com.rm.jkrm.MAINACTIVITY"); startActivity(mainScreen); } catch (InterruptedException e) { } finally { finish(); } } }; splashscreen.start();
这是你的问题UI线程睡觉不是一个很好的主意使用处理程序而不是
我认为它也可能导致例外.
Handler h=new Handler(); h.postDelayed(new Runnable() { public voID run() { // Todo auto-generated method stub startActivity(new Intent(Splash_Activity.this,Main_Activity.class)); finish(); } }, 2000); }
总结 以上是内存溢出为你收集整理的android – 在splashscreen之前的白色屏幕全部内容,希望文章能够帮你解决android – 在splashscreen之前的白色屏幕所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)