deprecated thread methods are not supported

前端 未结 3 940
轻奢々
轻奢々 2020-12-06 15:35

I am making one project where i need to display Home page and when home page displays, after that or continue with that 3 to 5 seconds my other welcome custom dialog is disp

3条回答
  •  庸人自扰
    2020-12-06 16:01

    In Android its better to use Handler for managing the Thread and Runnables

    Create an Handler instance

    Handler handler = new Handler();
    

    Create a Runnable thread

    Runnable runnable = new Runnable() {
    
            @Override
            public void run() {
                Log.d("runnable started", "inside run");
                handler.removeCallbacks(runnable);
                handler.postDelayed(runnable, 1000);
            }
        };
    

    And start the Runnable using Handler

    handler.postDelayed(runnable, 1000);
    

    And to stop the Runnable use

    handler.removeCallbacks(runnable);
    

提交回复
热议问题