Android implementation wait Interface
Message can return different types of values to meet different requirements.
| 0102030405060708091011121314151617181920212223242526272829303132 |
// Declare Variablesprivate Button b1;private ProgressDialog pd; // Define the handler objectprivate Handler handler =new Handler(){ @Override // Execute the handler method when a message is sent. public void handleMessage(Message msg){ super.handleMessage(msg); // Close the dialog box as long as it is executed. pd.dismiss(); }}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);} private void processThread(){ // Build a download progress bar pd= ProgressDialog.show(MainHandler.this, "Load", "Loading…"); new Thread(){ public void run(){ // Method of CEO time consumption in the new thread longTimeMethod(); // Send an empty message to handler after execution. handler.sendEmptyMessage(0); } }.start();} |
This method is concise and highly efficient.