1

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.

1 Answers1

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.

Community
  • 1
  • 1
Shahrzad
  • 1,062
  • 8
  • 26