Go back to previous screen on SslErrorHandler
Go back to previous screen on SslErrorHandler
So in my webview, I am showing an error dialog box for SSL security issues which Google had made compulsory. The code looks like below:
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error)
{
final AlertDialog.Builder builder = new AlertDialog.Builder(LaunchWVActivity.this);
builder.setMessage("SSL cert is invalid.Install a valid certificate or click continue to proceed.");
builder.setPositiveButton("continue", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
When a use clicks cancel
, my webview just stays on the same screen with white screen. I want to navigate user to previous screen from where he came from. I have tried adding a onCancelListener
, but it has not worked.
cancel
onCancelListener
Something like this
dialog.setCancelable(true);
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// dialog dismiss without button press
Log.d(TAG,"Cancel pressed");
webview.goBack();
}});
What am I missing here?
The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.
1 Answer
1
I resolved this issue. It was very straight forward approach with finishing the current activity. Initially I didn't realize, I could have my current activity as globally declared.
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
handler.cancel();
currentActivity.finish();
}
});
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment