7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Splash画面でpostDelayedして一定時間画面を表示する

Posted at
SplashActivity.kt
class SplashActivity : AppCompatActivity() {

    private val handler = Handler()
    private val runnable = Runnable {
        // write code that you want to delay. for example,
        startActivity(NextActivity.createIntent(this))
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        handler.postDelayed(runnable, 500)
    }

    override fun onStop() {
        super.onStop()
        handler.removeCallbacks(runnable)
    }

onPause()もしくはonStop()removeCallbacksしてあげないと、delay中にアプリを終了した場合に一定時間経ってアプリが勝手に立ち上がるという怪現象が起きます。気をつけましょう。👾

Is the splash screen necessary?

「postDelayedしてまでSplash画面を表示する必要があるか?」という検討は必要です。
今回は、毎起動時に同じ時間delayする画面を表示することでテンポよく画面遷移したいという理由で実装しました。

How much delay time the best?

個人の体感ですが、500〜1000msがベストだと思います。

Links

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?