Java 如何做出定时的意图

Java 如何做出定时的意图,java,android,android-intent,Java,Android,Android Intent,你好,我想让我的意图在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

你好,我想让我的意图在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);
    }
}
您可以使用此代码

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);
}

例如,要实现这一点,可以使用处理程序

new Handler().postDelayed(new Runnable(){
    public void run() {
       //CODE HERE
    }
}, 1000); //1000 mills is one second

试试这个

@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();
}
希望这对你有帮助