title: Codename One - ToastBar when "No connectivity detected"
body: <p>What is a correct approach to deal with Internet connection unavailability (that is common on mobile devices)? </p>
  
  <p>Maybe it's a big question (or maybe not), however I didn't find any Codename One tutorial / article / video or API to deal with an unstable Internet connection (that is the normality on mobile) without errors or unexpected behaviors. <em>I've found an app (Protonmail) that has a functionality that I would like to replicate in my apps. Please look at the following two screenshot: the first one is taken when the Internet connection is available, the second one when it's not available.</em></p>
  
  <p><a href="https://i.stack.imgur.com/I2Y9E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I2Y9E.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/Ll6jD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ll6jD.png" alt="enter image description here"></a></p>
  
  <p>I noted that the ToastBar appears not only when Internet is explicitly disabled, but every time that the server is not reachable. When the "No connectivity detected" message is shown, the app pauses the Internet activity, so no errors are generated (and the messages written by the user are not lost). When the app server returns to be reachable, the ToastBar disappears automatically (without pressing the "RETRY" button).</p>
  
  <p>What is a correct way to implement a similar functionality in Codename One, in a way that is as most as possible independent from the specific app? Is it possible to suspend the Internet activity of a Codename One app and then restore it? </p>
  
  <p>I'm imagining something like this:</p>
  
  <ul>
  <li>the app tries to do a simple request (like a ping) to a server every few seconds, implementing the performBackgroundFetch method;</li>
  <li>if there is no response in a fixed time (i.e. three seconds), the Internet activity is suspended and the ToastBar is shown;</li>
  <li>if there is response, the Internet activity is restored, the paused or failed downloads are restarted and the ToastBar disappears;</li>
  <li>ideally all of this should works also with a BrowserComponent.</li>
  </ul>