I have solved my problem with the following code, by using Thread.sleep()
in in onPostCreate()
and then check 5 times if my services are loaded by checking the size of the services Arraylist
is not 0
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
initDrawer();
int count = 0;
boolean mServicesReady = false;
boolean mPluginAvailable = false;
//to load the plugin correctly we have to let the thread sleep for 3 seconds
do {
if(count == 0){
try{
Thread.sleep(3000);
}catch(InterruptedException e){
Log.e(TAG, e.getMessage());
}
}
if(services.size() > 0){
mServicesReady = true;
//do something more
}else if(services.size() == 0){
//there are no services, throw a dialog that there are no services available
mServicesReady = false;
if(!mPluginAvailable)
noPluginAvailable();
mPluginAvailable = true;
}
count++;
}while((!mServicesReady) && (count < 5));
mDrawerToggle.syncState();
}