0

I want to refresh my UI when connection is established. While there is no connection, app shows a boring spinning dialog. When connection is back, it remains same. I just want to refresh my view in every aspect of my application. How can i implement such code that can be used in every activity, every fragment.

eden
  • 5,876
  • 2
  • 28
  • 43
  • possible duplicate of [Broadcast receiver for checking internet connection in android app](http://stackoverflow.com/questions/15698790/broadcast-receiver-for-checking-internet-connection-in-android-app) – shkschneider Apr 24 '15 at 15:55
  • checked that question. im already using those in my application. i just want a code that restarts my activity or fragment or such logic – eden Apr 24 '15 at 16:00

1 Answers1

1

You can achieve that by using Broadcast Receivers and the invalidate() method of the desired view you want to refresh. I'll leave the rest to you

ViewGroup vg = findViewById (R.id.mainLayout); // Any View you'd like to refresh
vg.invalidate(); // Refresh your view.

Another example found here in S.O.: Network listener Android

Community
  • 1
  • 1
VulfCompressor
  • 1,390
  • 1
  • 11
  • 26
  • Can you please explain? – eden Apr 24 '15 at 18:09
  • If you're not willing to cooperate and research a solution for your problem, then no explanation is to be given, right? @shkschneider mentioned Broadcast Receivers and you asked a code that restarts your activity or your fragment. It's not recommended to restart your activity just to refresh a single view. Instead, you create a ConnectivityManager and listen to its notifications. When you receive a notification that your cellphone has connectivity, you call the `invalidate()` method of the view you want to refresh. – VulfCompressor Apr 24 '15 at 18:21
  • Thank god finally an explanation – eden Apr 24 '15 at 18:39
  • By the way, remember to upvote the answer that helped you :) – VulfCompressor Apr 24 '15 at 18:42