Showing progress dialog while loading database in Android

后端 未结 2 474
感情败类
感情败类 2021-01-25 19:09

I am loading a database without problems in a SQLiteOpenHelper>>onCreate(SQLiteDatabase) method.

However, when I try to wrap the loading of the datab

2条回答
  •  孤街浪徒
    2021-01-25 19:20

    I would do this:

    private ProgressDialog progressDialog;
    private Handler handler;
    
    public yourConstructor(Context context){
        progressDialog = new ProgressDialog(context);
        progressDialog.setMessage("wait");
        progressDialog.setCancelable(true);
        handler = new Handler();
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) { 
        progressDialog.show();
        new Thread(new Runnable() {
            @Override
            public void run() {
    
                //your bd access here
    
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        progressDialog.cancel();
                    }
                );
            }
        }).start();
    }
    

提交回复
热议问题