Activity ProgressBar

I have two activities. The first performs the second.

Intent i = new Intent(MyOne.this, MyTwo.class); startActivity(i); 

Problem: My second activity does some hard startup work, so it starts a couple of seconds, and before it starts, I see a black screen.

Is it possible to set a progress indicator or some image instead of this black screen? Because I do not think that the user will wait for something that he does not know. I tried setting up the progressbar after setcontentview in the second action, but the progressbar only appears when the activity is fully running.

+4
source share
2 answers

I suggest you do this asynchronously using AsyncTask .

A brief example:

 ProgressDialog dialog; class YourTask extends AsyncTask<Void, Void, Void> { protected void onPreExecute() { dialog = ProgressDialog.show(...); } protected Void doInBackground(Void... unused) { try { // doSomethingHeavy(); // publishProgress(...); } catch(Exception e) { //... } return null; } protected void onProgressUpdate(Void... unused) { } protected void onPostExecute(Void unused) { dialog.dismiss(); } } 
+4
source

Are you sure you can. Check out AsyncTask and this tutorial for inspiration.

+1
source

All Articles