Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8302257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:14:29+00:00 2026-06-08T17:14:29+00:00

I am writing help system for my application. I use WebView inside AlertDialog. HTML

  • 0

I am writing help system for my application. I use WebView inside AlertDialog. HTML Help pages are stored in assets/ directory and have link reference to each other.
Minimal code to reproduce problem:

package qa.so.wv;

import android.content.Context;
import android.app.AlertDialog;
import android.webkit.WebView;
import android.content.DialogInterface;
import android.view.ContextThemeWrapper;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class DialogInformation {


    public void showFile(Context context, String file) {

        AlertDialog.Builder dialog = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.InformationDialogStyle));

        final Context ctx = context;    
        final WebView wv = new WebView(context);
        wv.setWebViewClient(
            new WebViewClient(){
                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
                        view.loadUrl(url);
                        return true;
                    }
            }
        );
        WebSettings settings = wv.getSettings();
        settings.setDefaultTextEncodingName("utf-8");
        wv.loadUrl(
            "file:///android_asset/"+file
            );

        dialog.setView(wv);

        dialog.setPositiveButton(
            context.getString(R.string.cont),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }
        ); 
        dialog.setNeutralButton(
            "Back",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    if (wv.isFocused() && wv.canGoBack()) {
                        wv.goBack();
                    } else {
                        Toast.makeText(
                            ctx, 
                            "No go back for Back button", 
                            Toast.LENGTH_LONG
                        ).show();
                    }
                }
            }
        );
        dialog.setOnCancelListener(
            new DialogInterface.OnCancelListener() {         
                @Override
                    public void onCancel(DialogInterface dialog) {
                    if (wv.isFocused() && wv.canGoBack()) {
                        wv.goBack();
                    } else {
                        Toast.makeText(
                            ctx, 
                            "No go back for system return 'hardware' button",
                            Toast.LENGTH_LONG
                        ).show();
                    }
                    }
            }
        );
        dialog.show();
    }

}

This class is used there:

package qa.so.wv;

import android.os.Bundle;
import android.app.ListActivity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.view.MenuItem;
import android.view.Menu;
import android.widget.Toast;
import android.webkit.WebView;

public class ShowArchive extends ListActivity
{

    // options menu items constants
    protected static final int MENU_HELP = Menu.FIRST+11;
    protected static final int MENU_QUIT = Menu.FIRST+16;


    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    }


    /* Create Menu Items */
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, MENU_HELP, 0, R.string.menu_help);
        menu.add(0, MENU_QUIT, 0, R.string.menu_quit);
        return true;
    }

    /* Handles Menu Item Selection */
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case MENU_HELP:
                DialogInformation dn = new DialogInformation();
                dn.showFile(    
                    this,
                    getString(R.string.help_file)
                );
                return true;    

            case MENU_QUIT:
                finish();
                return true;

        }
        return false;
    }

}

And two example pages from assets/ directory
page one:

<html>
<a href="second.html">link to 2-nd file"</a>
<p>
Some text.
</p>
</html>

and page two:

<html>
<p>2-nd file</p>
</html>     

I call “Help” from menu. Page one is displayed. I click to link. Page two correctly loaded.
When I click on “Back” button or hardware “Cancel” button Help dialog disappear instead of loading previously displayed page.

Help me solve this problem, please.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:14:30+00:00Added an answer on June 8, 2026 at 5:14 pm

    Try this

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                if(webView.canGoBack()) {
                     webView.goBack();
                } else {
                    finish();
                }
                return true;
            }
        }
        return super.dispatchKeyEvent(event);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing the help book for my application. As required, I have the CFBundleHelpBookName
I am writing an GL effect system in my application so i have a
I am writing some applications that require to have a Help Contents system tied
I need some help writing a regex. I have the following strings, xxx.yyy.wwwwwaaa_IN_123 xxx.rrrttttt_IN_12355
I am writing a stylesheet to use with my Compiled Help files. It looks
I'm writing a simple little application, which is a booking system. In the system
I'm writing an application which reads data from an XML file and I use
I'm not really writing an alarm clock application, but it will help to illustrate
I am writing an ASP.NET 4 application with C#. I have a Master Page,
I have been writing this Android application for the past few days and everything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.