1. 程式人生 > >android 開啟執行緒查詢資料,耗時操作

android 開啟執行緒查詢資料,耗時操作

 try {
            final Handler handler = new Handler();
            final Runnable callBack = new Runnable() {
                public void run() {
                    try {
                        //執行緒結束,處理
                    } catch (Exception ex) {
                        ex.getStackTrace();
                    }
                }
            };
            final Thread thread = new Thread() {
                @Override
                public void run() {
                    try {
                       //耗時操作
                    } catch (Exception ex) {
                    }
                    handler.post(callBack);
                }
            };
            thread.start();
        } catch (Exception ex) {
        }