Sounds as if you are running all your code in the UI thread. Would be nice with more code to be able to give a better example.
In your second activity:
private class BackgroundTask extends AsyncTask<Void, Void, Void> {
// Before running code in separate thread
@Override
protected void onPreExecute() {
// setup loading dialog
}
@Override
protected Void doInBackground(Void... arg0) {
// do long running code
return null;
}
// after executing the code in the thread
@Override
protected void onPostExecute(Void arg) {
// dismiss your dialog
}
}
And inside onCreate:
new BackgroundTask().execute();
Edit:
Now that I have seen your code I would suggest you try something like this:
private void setUpMap(){
map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.910526,32.804435),15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
new Handler().postDelayed(new Runnable() {
public void run() {
try {
String result = new MyNewTask().execute();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*
* you should move this call to onPostExecute
* then you will not need to call execute().get()
* which takes away the advantage of AsyncTask
* as it then is run on UI thread
*/
overlay.setOverlay(map);
}
}, 2000);
}
Setting up the map is an UI heavy task, so in my experience it looks nicer to wait a bit before loading markers etc. Furthermore this should enable the dialog to properly show before it is dismissed.