I try use below code to load an URL.
URL url = new URL(urlstr);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setConnectTimeout(10000);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
InputStream is = connection.getInputStream(); //spend lots of time
Because the line InputStream is = connection.getInputStream(); will spend some time.
So I want to show a loading dialog while it loading.
I can I do it?
In AActivity, below code to call BActivity.
Intent intent = new Intent(AActivity.this, BActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Window w = MyGroup.group.getLocalActivityManager().startActivity("BActivity", intent);
View view = w.getDecorView();
MyGroup.group.setContentView(view);
And BActivity is load URL and extract information.
The load code is in onCreate().
I try the answer code, the error Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@2afe9488 is not valid; is your activity running? shows.
You can achieve with the aysntask showing progress dialog as follows
In Oncreate :