Android sets the full-screen startup page to jump after a certain period of time

​Android
sets the full-screen startup page to jump after a certain period of time:
in the started WelcomeActivity:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import java.util.Timer;
import java.util.TimerTask;

public class WelcomeActivity extends AppCompatActivity {
    
    

    public static WelcomeActivity instance = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        setContentView(R.layout.activity_welcome);
        instance=this;
        final Intent it = new Intent(this, MainActivity.class); //你要转向的Activity
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
    
    
            @Override
            public void run() {
    
    
                startActivity(it); //执行
            }
        };
        timer.schedule(task, 1500); //1.5秒后
    }
}

To end WelcomeActivity you can do this in MainActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    
    
    super.onCreate(savedInstanceState);
    //getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
    setContentView(R.layout.activity_main);
    WelcomeActivity.instance.finish();//结束欢迎页activity
    //webView = new FragmentWebView();
    //initView();
    //initData();
    //clickHomeButton();//默认主页面
}

If you need to display it for a few seconds in the main Activity or have the function of clicking to enter the main Activity, you can add it yourself in WelcomeActivity.

Guess you like

Origin blog.csdn.net/qq_36369267/article/details/118765345