我嘗試在應用程序啓動時放置圖像。我有MainActivity
,使第二acivity這樣的:應用程序啓動時沒有啓動活動
public class SplashActivity extends Activity
{
private static final long DELAY = 3000;
private boolean scheduled = false;
private Timer splashTimer;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
splashTimer = new Timer();
splashTimer.schedule(new TimerTask()
{
@Override
public void run()
{
SplashActivity.this.finish();
startActivity(new Intent(SplashActivity.this, MainActivity.class));
}
}, DELAY);
scheduled = true;
}
@Override
protected void onDestroy()
{
super.onDestroy();
if (scheduled)
splashTimer.cancel();
splashTimer.purge();
}
}
在SplashAcitivity.xml
我補充一下:
android:background="@drawable/my_image"
和OFC我複製my_image到文件夾繪製
Android的工作室沒有下劃線在我的代碼,似乎好,但是當我運行這個應用程序時,應用程序像以前一樣工作,只用MainActivity。沒有想法從我如何解決它。
SplashActivity.this.finish();在startActivity之後調用此方法,並將splashactivity設置爲在啓動程序中顯示或不顯示? – Bali