当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to Notify user whenever the connectivity gets lost or regained?

问题描述:

My application has to update the server frequently, so, I run a service which checks whether or not the device is on coverage area, using ConnectivityManager and NetworkInfo, in every 3 minutes. It works fine... My doubt is, how to notify the user whenever the connectivity gets lost or regained? If there is an option for doing the updation automatically whenever the connectivity is regained, it will be great !!! Thanks in advance...

网友答案:

You can use handler to display toast message to user

You can have notifications from the service to the activity by way of interface class.

You can also use broadcastreciever so when connectivity is lost you can receive broadcast in your application by registering to it and display toast message accordingly.

I suggest you use service with handler. For more info on handlers have a look a the link. http://www.vogella.com/articles/AndroidPerformance/article.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: