如何使用线程从启动画面调用活动。只需用java代码指导我,即如何创建一个线程并调用我的下一个活动。
答案 0 :(得分:1)
如果要显示SplashActivity中的第二个活动: 注意: SplashActivity将成为manafist的启动活动
<activity android:name=".SplashActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
protected boolean _active = true;
protected int _splashTime = 5000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread splashTread = new Thread() {
@Override
public void run() {
try {
int waited = 0;
while(_active && (waited < _splashTime)) {
sleep(100);
if(_active) {
waited += 100;
}
}
} catch(InterruptedException e) {
// do nothing
} finally {
finish();
startActivity(new Intent("com.package.AppName.SecondActivity"));
}
}
};
splashTread.start();
}
希望这会对你有所帮助。