Codename One - ToastBar when “No connectivity detected”

那年仲夏 提交于 2019-12-06 15:55:36

You can detect a networking error in the NetworkManager class by using:

NetworkManager.getInstance().addErrorListener(e -> {
     // prevents the error from propagating into the ConnectionRequest class
     e.consume();

     ToastBar.showMessage("Connectivity error, retry?", FontImage.MATERIAL_ERROR, 
         ee -> ee.getConnectionRequest().retry());
});

As explained here: https://www.codenameone.com/manual/files-storage-networking.html

The toast bar code just prompts in a similar way and offers a retry on the connection request. Notice that this is the generic global approach.

This will not work for things like browser component which connects on its own without "us". In there you will need to handle errors in the JavaScript side.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!