Create a true splash screen

前端 未结 7 557
误落风尘
误落风尘 2020-12-09 05:21

How can I make a true splash screen in Android? I don\'t want timers or delays. Just a splash screen that is shown until your application has loaded.

7条回答
  •  感情败类
    2020-12-09 06:04

    Something like

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
    
        handler = new Handler();
    
        new AsyncTask() {
    
        @Override
        protected Void doInBackground(Void... params) {
                //Do some heavy stuff
                return null;
            } 
    
            @Override
            public void onPostExecute(Void result){
                handler.post(new Runnable(){
                     @Override
                     public void run(){
                         setContentView(R.layout.main);
                     }
                });
            }
       }.execute();
    }
    

提交回复
热议问题