I am creating a mobile app which updates the local database from a remote database by using an AsyncTask. This works fine, except the view (spinners and table data) relies on data being in the local database. This if fine after the initial run of the asynctask but the screen is blank on first load.
I have:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sp = getSharedPreferences("***", 0);
boolean initalSync = sp.getBoolean("***.android.db.inital", false);
if(initalSync==false){
AsyncTaskRunner backgroundTask = new AsyncTaskRunner(this);
backgroundTask.execute();
}
Because the updating of the local database from the remote database from the remote database is a background task and is performed if the initalsync Boolean is false.
The fragment displays information based on the local database and is the default / startup view.
I currently protect it by running
if(initalSync==true){
// DISPLAY TABLE OF DATA
}
I know I cant "pause" the thread and I cant perform the displaying of the local table data in the onPostExecute as I will update the database at other times.
I basically wish to display a progress bar and wait until the asynctask is done and then allow the rest of code to run
Any ideas?