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 8859625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:06:45+00:00 2026-06-14T15:06:45+00:00

I have tried many things and keep receiving a crash error on my Android

  • 0

I have tried many things and keep receiving a crash error on my Android app. My app is a simple webwrapper app using the webview function. Basically, I have webview displaying a website that has a mobile site. What I am trying to do is make it so that

  1. back button will take the user back to the previous screen
  2. back button on the app (which I put in the layout), will also take the user to the previous screen.
  3. I also want the home button on the phone to go back to the home screen and exit the app completely.
  4. Lastly, the mobile app has external links that should be going into a browser and not staying within the app (example: visit full site).

Below is my code, any help for any of the 1-4 questions would be helpful! :-)! If you need to see my XML dont hesitate to ask.

package com.example.envision;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.ProgressBar;

public class Envision extends Activity {
/** back button functionality NOT WORKING CAUSES A CRASH
WebView webview;
@Override
   public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(event.getAction() == KeyEvent.ACTION_DOWN) {
            switch(keyCode)
            {
            case KeyEvent.KEYCODE_BACK:
                if(webview.canGoBack() == true){
                    webview.goBack();
                } else {
                    finish();
                }
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    } */

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_envision);

WebView webview = (WebView) findViewById(R.id.webView1);

WebSettings websettings = webview.getSettings();

websettings.setJavaScriptEnabled(true);
websettings.setSaveFormData(false);
websettings.setSavePassword(false);

webview.loadUrl("http://envisionfinancial.ca/m/");
webview.setHorizontalScrollBarEnabled(false);
webview.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
webview.setBackgroundColor(128);

webview.setWebViewClient(new EnvisionWebViewClient());

webview.setDownloadListener(new DownloadListener() {
    public void onDownloadStart(String url, String userAgent,
            String contentDisposition, String mimetype,
            long contentLength) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        startActivity(intent);
        }


});

}

public void visible(){

WebView webview = (WebView) findViewById(R.id.webView1);

ImageView logo = (ImageView) findViewById(R.id.imageView1);

ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar1);

webview.setVisibility(10);

logo.setVisibility(0);

bar.setVisibility(0);

}

public void unvisible(){

WebView webview = (WebView) findViewById(R.id.webView1);

ImageView logo = (ImageView) findViewById(R.id.imageView1);

ProgressBar bar = (ProgressBar) findViewById(R.id.progressBar1);

webview.setVisibility(0);

logo.setVisibility(10);

bar.setVisibility(10);

}


private class EnvisionWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url){
    webview.loadUrl(url);
    return true;
}


@Override
public void onReceivedError(WebView view, int errorCode,
    String description, String failingUrl) {
// TODO Auto-generated method stub
view.loadUrl("http://envisionfinancial.ca/m/");
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {

visible();

}

@Override
public void onPageFinished(WebView view, String url) {

unvisible();

}

}
/** exits the app?? review */
public void finishActivity(View v) {
finish();

}
}
  • 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-14T15:06:46+00:00Added an answer on June 14, 2026 at 3:06 pm

    Are you getting a NullPointerException in onKeyDown? That is because you do not assign the WebView to the instance variable:

    webview = (WebView) findViewById(R.id.webView1);
    

    The back functionality can be implemented like this:

    public void onBackPressed() {
        if (webview.canGoBack())
            webview.goBack();
        else
            super.onBackPressed();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried so many things, cannot figure this out, I am using this
I have tried many things, such as the 2 references: http://developer.android.com/training/basics/fragments/communicating.html & http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity along
I have tried so many different things and I keep searching but I find
This should be really simple, but I have tried many solutions posted on the
I am using jQuery fullcalendar plugin , I have tried altering this many different
I have tried many things to get this working correctly but I can't Here
I have tried many things, but I'm still not getting this to work. Here's
I've seen similar things posted everywhere, and have tried many of them over the
I have tried many permutations but they all don't seems to work well. Am
I have tried many options mentioned in the previous messages/forums.None of them seem to

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.