How to show splash image while loading activity

前端 未结 3 1498
感动是毒
感动是毒 2021-01-02 19:54

I have an activity that contains many UI views. In its onCreate method, I found single line of setContentView takes 8-12 seconds to be complete. So I want t

3条回答
  •  日久生厌
    2021-01-02 20:25

    Below is the simple code for creating splash screen using CountDownTimer class

    public class SplashDialogActivity extends Activity {
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            // Be sure to call the super class.
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.layout);
          counter.start();
        }
        MyCount counter = new MyCount(5000, 1000);
     public class MyCount extends CountDownTimer{
                public MyCount(long millisInFuture, long countDownInterval) {
                super(millisInFuture, countDownInterval);
                }
    
                @Override
                public void onFinish() {
                    go_back();
                }
    
                @Override
                public void onTick(long millisUntilFinished) {
    
    
    
                  }
         }
    
     public void go_back()
            {
              counter.cancel();
    
                        Intent i=new Intent(this,account.class);
                        i.putExtra("first_time", true);
                        startActivity(i);
    
                this.finish();
            }
    }
    

提交回复
热议问题