你好我想让我的意图在1秒之后发生,它的目的是在我的应用程序开始时的闪存屏幕。
//Creates a new screen for the painter to select what route he wants to go down. A flash screen.
public void nScreen(View view)
{
Intent intent = new Intent(MainActivity.this, Main22Activity.class);
startActivity(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
答案 0 :(得分:0)
您可以使用此代码
private final int SPLASH_DISPLAY_LENGTH = 1000;
@Override
protected void onResume() {
super.onResume();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MainActivity.this.finish();
Intent mainIntent = new Intent(MainActivity.this, Main22Activity.class);
startActivity(mainIntent);
}
}, SPLASH_DISPLAY_LENGTH);
}
答案 1 :(得分:0)
要实现这一点,您可以使用处理程序,例如
new Handler().postDelayed(new Runnable(){
public void run() {
//CODE HERE
}
}, 1000); //1000 mills is one second
答案 2 :(得分:0)
试试这个
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread thread = new Thread() {
public void run() {
try {
// Thread will sleep for 1 seconds
sleep(1000);
// After 1 seconds redirect to another intent
Intent intent = new Intent(MainActivity.this, Main22Activity.class);
startActivity(intent);
//Remove activity
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
};
// start thread
thread.start();
}
希望这有助于你