package com.example.test;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
private Intent myintent;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
myintent = new Intent(this, MainActivity.class);
splashScreen(1000); }
public void splashScreen (final int x)
{
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(x);
} catch (InterruptedException e) {
e.printStackTrace();
}
startActivity(myintent);
finish();
}
}).run();
}
}
コードがありますが、ここに問題があります。SplashScreen はスプラッシュ XML レイアウト ファイルのコンテンツ ビューを取得しません。これはスレッドの問題であり、どういうわけかスレッドが setContentView メソッドの前に実行されるのではないかと疑っています。そのメソッドはコード内のスレッドの実行メソッドの前に配置されているため、このように考えるのは非論理的ですが、このスプラッシュ スクリーンが機能しない理由が不足しているようです。