Image on start up / loading

后端 未结 3 2044
难免孤独
难免孤独 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:17

    Your needs is callign Splash Screen. Here is my splash screen code.

    Just add new activity and set application for opening this activity.

    public class SplashActivity extends DeviceInfoAbstractActivity {

    @SuppressLint("MissingSuperCall")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState, R.layout.activity_splash);
    
        passScreen();
    }
    
    private void passScreen() {
    
        new CountDownTimer(1000, 2000) {
    
            @Override
            public void onTick(long millisUntilFinished) {
    
            }
    
            @Override
            public void onFinish() {
    
                Intent intent = RDAIntentHelpers.getClearCacheIntent();
    
                intent.setClass(SplashActivity.this, MainActivity.class);
    
                startActivity(intent);
    
            }
        }.start();
    }
    
    @Override
    public void onBackPressed() {
        //no exit
    }
    }
    

    and this my getClearCacheIntent() method

    public static Intent getClearCacheIntent() {
    
        Intent intent = new Intent();
    
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    
        return intent;
    }
    

    after these, your splash screen stays on screen for 2 seconds. Do whatever you want =)

    0 讨论(0)
  • 2021-02-06 00:26

    This start up image also known as 'splash screen'. Here you can find how to make splash screen.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题