Image on start up / loading

后端 未结 3 2070
难免孤独
难免孤独 2021-02-05 23:57

I ma developing an app, which at the moment when it is loading from the onCreate point, I just have a black screen (until the app gets its footing). Looking at other apps they h

3条回答
  •  忘了有多久
    2021-02-06 00:35

    Create a new activity that displays the image for a few seconds and redirects to your main activity:

    public class SplashActivity extends Activity
    {
        private static final long DELAY = 3000;
        private boolean scheduled = false;
        private Timer splashTimer;
    
        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.splash);
    
            splashTimer = new Timer();
            splashTimer.schedule(new TimerTask()
            {
                @Override
                public void run()
                {
                    SplashActivity.this.finish();
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                }
             }, DELAY);
           scheduled = true;
        }
    
        @Override
        protected void onDestroy()
        {
            super.onDestroy();
            if (scheduled)
                splashTimer.cancel();
            splashTimer.purge();
        }
    }
    

    Set your image as the background for this activity. Hope that helps. Good luck!

提交回复
热议问题