Show ProgressDialog in a Service class

后端 未结 1 1657
慢半拍i
慢半拍i 2021-01-14 14:05

I am using a Service to connect to a network using a AsyncTask. I want to show a ProgressDialog till the app is connected to the network. But how can I do this?

My S

相关标签:
1条回答
  • 2021-01-14 14:55

    So a service is NOT the UI you have to use the observer pattern. Your activity have to register a listener in the service so that the service can inform the activity for special events (like start loading or finish loading).

    You have to add following intercae into your service class:

        public interface serviceObserver {
            public void startLoading();
            public void stopLoading();
        }
    

    Your activity has to implement serviceObserver. Your service has to store a instance from serviceObserver which is created in the activity. If your service is running without your activity i recommend to use broadcast receiver for communication.

    0 讨论(0)
提交回复
热议问题