How to set a time for progressive dialog? - android

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 :)

Related

how to know a dialog is closed in robotium?

I am doing a test project using robotium. I need to pause excecution of all the remaining code till the progress dialog is closed. Now i am hardcoding the time. But the problem is sometimes progress dialog will not close within that time period.how can i do this?
You can use the waitForDialogToClose(long timeout) method.
Hope this helps.

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 Activity Indicator

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

Bypass modal Android dialogs by clicking buttons twice fast enough?

Let's say we have two buttons, each with a OnClickListener. Each of listeners show a ProgressDialog and do some background work. (Behind the scene is an AsyncTask, the dialog is opened in onPreExecute. I don't think it matters, just for the record...). Let's say there is some rule saying no more than one background worker may be active at any given time.
My assumption was that the Dialog prevents two background workers running at the same time. I thought the modal dialog blocks the UI and it's not possible to click another button after the show() method of the dialog is called. I was wrong.
If you click the buttons fast enough, it's possible to trigger both background workers (almost) at the same time. The log shows that it's possible to click two Buttons within a 150 ms time span despite the Dialog:
04-14 18:34:04.390: DEBUG/greenrobot(1860): Clicked: 2131034112
04-14 18:34:04.470: DEBUG/greenrobot(1860): doInBackground2: 2131034112
04-14 18:34:04.540: DEBUG/greenrobot(1860): Clicked: 2131034113
04-14 18:34:04.570: DEBUG/greenrobot(1860): doInBackground2: 2131034113
The dialog code looks like this:
progressDialog = new ProgressDialog(currentActivity);
progressDialog.setMessage(msg);
progressDialog.show();
What did I miss? I hope I missed something really stupid, because if not, I cannot think of a nice and solution preventing UI interaction after the click. Synchronizing the background workers is not a solution because the UI and scenario is more complex.
Disable the button after it is clicked, until it is safe to be clicked again.
show() is asynchronous. The dialog will not appear immediately upon the call to show(). It will occur moments later.

Changing Progress Dialog Message While Running

I've got a fairly simple issue I'm not sure how to resolve. I want to change the message text of a Progress Dialog while it's running and showing. An example of this would be something like a "time remaining" counter that would count down while the progress animation is spinning. I'm not sure how I would approach this because doing progressDialog.setMessage(String), even within a running thread, will not change anything in the Dialog itself. Thank you!
You might want to check this question out.
In short: You need to create a little Runnable which you can execute on the UI thread using runOnUiThread...

Categories

Resources