我正在使用一个Android Native应用程序,该应用程序在启动后会加载webView。我正在实现在与服务器之间的连接丢失的逻辑,而在两者之间使用应用程序时丢失了,然后在弹出窗口中显示重试按钮。点击重试时,它将验证连接是否恢复,然后恢复,否则将在加载指示器5秒钟后显示带有重试的弹出窗口。启动时可以通过证明主页URL来实现。一旦应用程序之间建立连接,如何恢复或重新加载用户离开的页面?
public void onNoConnectionError() {
loadPageWhereUserLeft(true);
}
private void loadPageWhereUserLeft(boolean retry) {
retryButton.setVisibility(View.INVISIBLE);
infoText.setVisibility(View.INVISIBLE);
splash_screen_overlay.setVisibility(View.INVISIBLE);
mProgressBar.setVisibility(View.VISIBLE);
tries = retry ? tries + 1 : tries;
headCheckAsyncTask = new HeadCheckAsyncTask(checkUrlHandler, retry);
headCheckAsyncTask.execute(mHomePageUrl); // Is this url fine as this
// checking the connectivity
checkUrlHandler.postDelayed(checkUrlTimeoutRunnable,
HeadCheckAsyncTask.CONNECTION_TIMEOUT);
/* Written the logic in //OnPostExecute() which returns true is
status.code == 200 */
}
public void onRetryClick(View v) {
switch (v.getId()) {
case R.id.retry_button: {
infoText.setText("");
mProgressBar.setVisibility(View.VISIBLE);
retryButton.setVisibility(View.GONE);
splash_screen_overlay.setVisibility(View.INVISIBLE);
loadPageWhereUserLeft(true);
break;
}
}
}