How to pause / sleep thread or process in Android?

后端 未结 12 1051
故里飘歌
故里飘歌 2020-11-22 05:49

I want to make a pause between two lines of code, Let me explain a bit:

-> the user clicks a button (a card in fact) and I show it by changing the background of thi

12条回答
  •  野的像风
    2020-11-22 06:34

    This is my example

    Create a Java Utils

        import android.app.ProgressDialog;
        import android.content.Context;
        import android.content.Intent;
    
        public class Utils {
    
            public static void showDummyWaitingDialog(final Context context, final Intent startingIntent) {
                // ...
                final ProgressDialog progressDialog = ProgressDialog.show(context, "Please wait...", "Loading data ...", true);
    
                new Thread() {
                    public void run() {
                        try{
                            // Do some work here
                            sleep(5000);
                        } catch (Exception e) {
                        }
                        // start next intent
                        new Thread() {
                            public void run() {
                            // Dismiss the Dialog 
                            progressDialog.dismiss();
                            // start selected activity
                            if ( startingIntent != null) context.startActivity(startingIntent);
                            }
                        }.start();
                    }
                }.start();  
    
            }
    
        }    
    

提交回复
热议问题