android中新活动的自动启动
我正在创建一个android应用程序。我有一个android中新活动的自动启动,android,android-activity,Android,Android Activity,我正在创建一个android应用程序。我有一个徽标屏幕(活动),然后是我的主屏幕(另一个活动)。我希望当我启动我的应用程序时,我的徽标屏幕应该出现,然后在2秒钟后自动出现我的主屏幕。有谁能建议我该怎么做吗?请用这个 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; public class Logo extends Ac
徽标屏幕(活动)
,然后是我的主屏幕(另一个活动)
。我希望当我启动我的应用程序时,我的徽标屏幕应该出现,然后在2秒钟后自动出现我的主屏幕。有谁能建议我该怎么做吗?请用这个
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class Logo extends Activity {
protected boolean _active = true;
protected int _splashTime = 2000;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
finish();
Intent i3 = new Intent(Logo.this, Home.class);
startActivity(i3);
}
}, _splashTime);
}
}
您可以使用TimerTask。在TimerTask上,在2分钟后安排任务。然后执行以下任务 要使用计时器任务,请参阅链接
LogoScreen.this.startActivity(新意图(LogoScreen.this,HomeScreen.class)) 您可以使用倒计时在一段时间后自动打开活动 当倒计时结束时,在
onFinish()
方法中可以编写
编码以更改活动。对于未来的读者,您也应该覆盖
onBackPressed()
,否则,如果用户在启动屏幕中关闭应用程序(按后退按钮),则下一个活动仍将打开,因为处理程序在后台运行。