i want to make a loading screen while the android app is doing a huge process like finding prime numbers in a range.it takes a long time for the process to done and i want to appear a loading screen or progress bar while it is doing the huge process. here are the codes of my app:
You can add a simple ProgressDialog.
ProgressDialog progress = new ProgressDialog(this);
progress.setTitle("Loading..");
progress.setMessage("Please wait...");
progress.setCancelable(true);
when you need to start it, call
progress.show();
when you need to dismiss it, call
progress.dismiss();
Related
I'm looking for the best way to lock all the buttons and fields on my view while the application is waiting for server to respond. I created an activity that will be a little transparent and has a loading bar/spinner on it. The activity stops itself when the respons is received.
Is there any other, better way to do that. All I found on forums and such are 3-4 years old posts that use outdated/deprecated methods.
Any suggestions about how I should lock the activity and let the user know something is going on and that he/she should wait for it to finis...
Thank you
How about just using a ProgressDialog?
pd = new ProgressDialog(context);
pd.setTitle("Processing...");
pd.setMessage("Please wait.");
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.show();
And then when your results come up, just hide the ProgressDialog and launch your new Activity.
Simply you can use Android AsyncTask Class like,
Initially disable all of your views (using View.setEnabled(false))
Check your Server Response (Hope you are using AsyncTask class)
Simply show Progress Dialog (non cancelable) until you can get the response from server (in AsyncTask's onPreExecute() method)
progressDialog = new ProgressDialog(Activity.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("Please Wait...");
progressDialog.show();
Finally, enable your all views within AsyncTask's onPostExecute() once you get Response (using View.setEnabled(true))
I want to select and upload images from my sdcard of device using my application while it is selecting and uploading the image i wanted to show progress dialog and once uploading is complete dismiss the progress dialog but it should show the dialog until unless file is uploaded completely no matter what is the size of image.
Try using AsyncTask.
Show Progress dialog in onPreExecute()
Upload your image in doInBackground()
dismiss the progress dialog in onPostExecute()
The flow will be, first of all onPreExecute() will be called then doInBackground() will be called and when whatever task being done in doInBackground() will finish, onPostExecute() will be called. You can use this to achieve what you want.
You can use Service to perform long time operation.
We can use AsynckTask, Services, Intent Service etc for performing long running operation.
Does anyone know how to create a similar animation to the login animation used in the Google Plus Android app?
Is there something similar in the Android SDK that I can use? Or should I just build it from scratch? I'm interested especially in the fact that the UI behind the modal animation is dimmed and disabled.
Thank you.
Are you taking about that progress dialog spinning thingy that says "signing in"? That's not a custom animation at all, it's a common widget.
Here's the code:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Signing in...");
progressDialog.show();
//... complete sign in...then
progressDialog.dismiss();
A ProgressDialog done this way, automatically takes care of dimming/blurring the background. You should really read about dialogs: http://developer.android.com/guide/topics/ui/dialogs.html
To show the progression with an animated progress bar:
1- Initialize the ProgressDialog with the class constructor, ProgressDialog(Context).
Set the progress style to "STYLE_HORIZONTAL" with setProgressStyle(int) and set any other properties, such as the message.
2- When you're ready to show the dialog, call show() or return the ProgressDialog from the onCreateDialog(int) callback.
3- You can increment the amount of progress displayed in the bar by calling either setProgress(int) with a value for the total percentage completed so far or incrementProgressBy(int) with an incremental value to add to the total percentage completed so far.
For example, your setup might look like this:
ProgressDialog progressDialog;
progressDialog = new ProgressDialog(mContext);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Loading...");
progressDialog.setCancelable(false);
The setup is simple. Most of the code needed to create a progress dialog is actually involved in the process that updates it. You might find that it's necessary to create a second thread in your application for this work and then report the progress back to the Activity's UI thread with a Handler object. If you're not familiar with using additional threads with a Handler, see the example Activity below that uses a second thread to increment a progress dialog managed by the Activity.
I am programming for an Android application. while clicking a button, it calls a service to display the necessary contents. For calling the service and to parse the XML data present in that service it takes nearly 5 to 10 seconds. In these 5 seconds time period I need to display an activity Indicator with a text stating that "Loading. Please wait...". This part works fine for iPhone. But not in Android.
Any help would be appreciated..
Thanks
Check this. Look at "Creating a ProgressDialog" section. Try to parse the XMLs in AsyncTask. When you start the task just show the progress dialog. When the task finishes - hide the progress dialog.
if you want to show a message when your service is running you can use Progress Dialog for that.
ProgressDialog dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Your message..");
dialog.show();
to dismiss this progress dialog use
dialog.dismiss();
I have an issue with my ProgressDialog object. When I show it first time, it is spinning, but after I dismiss it and show it again, the dialog is static, it it not spinning... Can you please tell me why? All of this happens in the UI thread. Thanks
are you doing any processing in the UI thread during the second show of the ProgressDialog? If so, you need to move the processing to a background thread. Otherwise, the progress dialog does not get the CPU to update(spin) itself.