I have a java method which connects with a server and getting data online.I want to know how do I show a loading gif image until this process end? Tankful if u have a good solution.
Asked
Active
Viewed 963 times
1
-
possible duplicate of [Creating a nice "LOADING..." animation](http://stackoverflow.com/questions/7634402/creating-a-nice-loading-animation) – Dror Bereznitsky Apr 12 '14 at 11:22
-
I can run a loading gif image like this.But i want to do it until the method execution end. can u please explain how could i do it.How can i capture the execution time of a particular method? – SHdinesh Madushanka Apr 12 '14 at 11:27
-
you need to run something in the background or wait for it to execute? – Dror Bereznitsky Apr 12 '14 at 11:56
-
I need to wait my method untill it execute. – SHdinesh Madushanka Apr 12 '14 at 12:20
1 Answers
0
You can not capture the exact execution time for a method, so use this logic This will require:
//show loading GIF
//do your job
//hide loading image
but in many cases if you are doing a task that may through Exception
then your progress will remain there although you method is done. So I use this
public void myTask(...) {
showProgress();
try {
//do your job
} catch (Exception e) {}
hideProgress();
}
private void showProgress() {
//progress show code here
}
private void hideProgress() {
//code here
}
You can see the pretty much good progress animation From here and add the show progress code and hide progress code on the relevant method.
By making tow methods one showProgress
and hideProgress
, you can simply call them in any method of your class, need not to write code again and again.