Android Activity Indicator - android

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();

Related

How to make a loading screen while doing a huge process

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();

Progress Dialog is not spinning enough in asynctask in android

I am using progress dialog in my Asynctask class. I put progressdialog.show() on onpreExecte() method of asynctask and dismissing the dialog in onPostExecute. My problem is the wheel in dialog is stops after 2-3 seconds but my background process is working. Can anyone help me to solve this problem? I want to spin the wheel until the background process is over.
Check tutorials how to do asynchronus task in Android:
link
link
link
link
link.
And here are some other StackOverflow questions that are similar:
Progress dialog problem in Android
Progress Dialog on open activity
Progress Dialog while starting new activity
Android: Progress Dialog spinner not spinning
Updating progress dialog
android: showing a progress dialog
Just a guess, but it seems to me that starting the progress dialog INSIDE the AsyncTask causes the dialog to work on the AsyncTask thread, instead of the UI thread.
I suggest moving the progressdialog.show() to just before you call execute() in your Activity.

Easiest way to implement visual-feedback/busy-indicator in android

I am creating an app MainActivity that can calculate a report from its database to be shown in ReportActivity. All report calculation is done in ReportActivity.onCreate().
When the user click on MainActivity-s menu "generate report" the menĂ¼ remains open for 2 secs until ReportActivity.onCreate() has finished and the report becomes visible.
What is the easiest way to give the user some visual feedback?
I already found ProgressDialog onCreate that shows a progressdialog while doing all calculation in an AsyncTask.
I wonder if there is some easier way to give the user some visual feedbak that the menue was successfully clicked and that the device has not crashed.
in ms windows i would use a waitcursor (hour-glass)
I already tried to open a ProgressDialog() in oncreate of the ReportActivity
final ProgressDialog progressDialog = ProgressDialog.show(this, "MY Dialog", "Please wait...");
but it is not shown at all.
Update final solution:
As the answerss suggested I implemented an AsyncTask for the processing following this tutorial
based on this codesample
You need to move your long-running code into a background thread. Long-running code on the UI thread will lock up the UI, which causes the user to think the app is frozen/crashing. Look into using AsyncTask. This allows you to run a process on a background thread and also give visual feedback to let the user know that your app is working.
Design a layout with ProgressDialog. Use setContentView(Progressdialog). Count time for 2-4 seconds (you choice) again set your older layout in setContentView. Why don't you use AsyncTask?
Use a bar or circle activity indicator. From the official design guide:
Activity indicators are for operations of an indeterminate length.
They ask users to wait a moment while something finishes up, without
getting into specifics about what's happening behind the scenes.

Android: How to create the Google Plus login animation?

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.

How to set a time for progressive dialog?

I want to set a time (for example 5 seconds) for ProgressDialog in my android app. How can I do this?
I think you can use handler for this.Firstly start show dialog and at this time sendMessageForDelay(event_id,5*1000) and at handleMessage you check dialog is showing or not.If showing you dismiss it.Goodluck :)

Categories

Resources