0

I have a phonegap webview loading an external page. I am trying to override the back button so the user can go back on the website, and when they hit the first page it exists the application. I saw this link about disabling the cache, Strange webview goBack issue in android but it did the same thing as well.

package com.myapp.net;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import org.apache.cordova.DroidGap;
import android.webkit.WebView;
import android.webkit.WebSettings;

public class Shop extends DroidGap {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_shop);
        super.setBooleanProperty("loadInWebView", true);
        super.loadUrl("http://mywebappurl.com/");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_shop, menu);
        return true;
    }

    @Override
    public void onBackPressed()
    {
        WebView webView1 = (WebView) findViewById(R.id.webView1);
        webView1.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        if(webView1.canGoBack())
            webView1.goBack();
        else
            super.onBackPressed();
    }
}
Community
  • 1
  • 1
stampede76
  • 1,521
  • 2
  • 20
  • 36

1 Answers1

1

I'm guessing that webView1 is null because there isn't a View with the id webView1.

Perhaps you want to uncomment this line:

 //setContentView(R.layout.activity_shop);

But I've never used PhoneGap so I could be wrong.

Sam
  • 86,580
  • 20
  • 181
  • 179