I have a class inheriting from AsyncTask :
class LoadData extends AsyncTask<Void, Void, Integer> { private Context mContext; private String baseName; private DataBase dataBase; private SQLiteDatabase db; private ProgressDialog progressDialog; LoadData(Context context, String name) { mContext = context; baseName = name; progressDialog = new ProgressDialog(mContext); progressDialog.setTitle("Загрузка"); progressDialog.setMessage("Идет загрузка..."); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setIndeterminate(true); } @Override protected void onPreExecute() { super.onPreExecute(); progressDialog.show(); } @Override protected Integer doInBackground(Void... params) { for (int i = 0; i < 10000; i++) { dataBase = new DataBase(mContext, baseName); db = dataBase.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put("text_1", "text 1"); cv.put("text_2", "text 2"); cv.put("text_3", "text 3"); cv.put("text_4", "text 4"); cv.put("text_5", "text 5"); db.insert("text", null, cv); db.close(); dataBase.close(); } return 0; } @Override protected void onPostExecute(Integer result) { super.onPostExecute(result); progressDialog.dismiss(); } } I call it in activity and wait for it to finish like this (after calling setContentView ):
LoadData loadData = new LoadData(this, "myBase"); loadData.execute(); try { int num = loadData.get(); } catch (Exception e) {} The problem is that the dialogue does not appear. Just a black screen, but in the log you can see that the stream is working!
How to make this dialogue appear, and the activity to wait for its completion?
AsyncTaskwith all the data loaded. If it is half full, it will be half restored, completely full, I will restore it completely and immediately get the result. And how to do it inActivityI do not know. Yes, and I tried to do the same in activity, but it hung and its dialogue did not even have time to appear. - user189127AsyncTaskitselfAsyncTaskmeaningless - it does not have access to the UI and, accordingly, will not display anything, as you have already noticed. Thus, once again you come up with a self-made crutch and ask questions about it, instead of solving the real problem - how to maintain the state of the asynchronous while turning the activation. - pavlofffAsyncTask'a, when I rotate the screen, I already understood, but how to make it show the dialogue ... Now I’ll go try the @Saidolim option. - user189127