How to handle screen orientation change when progress dialog and background thread active?

前端 未结 28 1838
轮回少年
轮回少年 2020-11-22 07:03

My program does some network activity in a background thread. Before starting, it pops up a progress dialog. The dialog is dismissed on the handler. This all works fine, exc

28条回答
  •  半阙折子戏
    2020-11-22 08:00

    I am a fresher in android and I tried this and it's worked.

    public class loadTotalMemberByBranch extends AsyncTask {
            ProgressDialog progressDialog = new ProgressDialog(Login.this);
            int ranSucess=0;
            @Override
            protected void onPreExecute() {
                // TODO Auto-generated method stub
                super.onPreExecute();
                progressDialog.setTitle("");    
                progressDialog.isIndeterminate();
                progressDialog.setCancelable(false);
                progressDialog.show();
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
    
            }
            @Override
            protected Void doInBackground(Void... params) {
                // TODO Auto-generated method stub
    
                return null;
            }
            @Override
            protected void onPostExecute(Void result) {
                // TODO Auto-generated method stub
                super.onPostExecute(result);
                progressDialog.dismiss();
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
            }
    }
    

提交回复
热议问题