Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting AsyncTask progress for SQLite - cannot get progress percentage
    primarykey
    data
    text
    <p>I have created a splash screen for my app to hide the periodic insertion (after publishing updates) of a large number of records into the different tables of my app's SQLite database. I have been implementing an AsyncTask to handle the insertion off of the UI thread.</p> <p>I need to create a ProgressDialog (with progress bar, not the simple spinning wheel) to inform the user of the current progress percentage for the insertion operations.</p> <p>In most examples for setting the dialog's progress bar, the counter variable for the for loop representing the lengthy operation, or the percentage of file download is used to set this progress for the dialog. However, since insertions into different tables may take different amounts of time (depending on number of columns, etc), this approach appears to fail. The closest solution I could see would be to write a publishProgress(some_percentage) line after every record insertion in my doInBackground() method, using the % of records inserted as the parameter for publishProgress(), but this seems like a terribly inelegant and inefficient practice.</p> <p>The current code for my AsyncTask implementation is below. Any suggestions for the best practice of determining the current progress percentage would be greatly appreciated. Thanks!</p> <pre><code>private class InsertionAction extends AsyncTask&lt;Void,Integer,Void&gt; { Context context; private ProgressDialog dialog; private ForwardAction(Context context) { this.context = context; dialog = new ProgressDialog(context); } @Override protected void onPreExecute() { super.onPreExecute(); this.dialog.setMessage("Initializing Database. Please Wait..."); this.dialog.show(); this.dialog.getWindow().setGravity(Gravity.BOTTOM); this.dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); this.dialog.setCancelable(false); } @Override protected Void doInBackground(Void... params) { // Large block of record insertions return null; } @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); // Forward to the main activity if (dialog.isShowing()) { dialog.dismiss(); } animatedTransition(SPLASH_DISPLAY_TIME/2); } @Override protected void onProgressUpdate(Integer... values) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload