Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to refresh WebView?

Ok. I have looked EVERYWHERE and my little brain just can't understand a better way to refresh an activity. Any suggestions that I can understand would be great. :)

Here is the java code:

package com.dge.dges;  import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.webkit.WebView; import android.widget.Button;  public class dgeActivity extends Activity {      WebView mWebView;      /** Called when the activity is first created. */     @Override     public void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.main);          mWebView = (WebView) findViewById(R.id.webview);         mWebView.getSettings();         mWebView.loadUrl("http://www.websitehere.php");                  Button newButton = (Button)findViewById(R.id.new_button);         newButton.setOnClickListener(new View.OnClickListener() {             public void onClick(View v) {                 Intent intent = new Intent(dgeActivity.this, dgeActivity.class);                 startActivity(intent);             }         });     } } 

And here is the main.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/RelativeLayout"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#000000">      <WebView         android:id="@+id/webview"         android:layout_width="fill_parent"          android:layout_height="wrap_content"         android:scrollbars="none"/>      <Button         android:id="@+id/new_button"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_alignParentBottom="true"         android:layout_centerHorizontal="true"         android:text="Refresh"/>  </RelativeLayout> 

I don't like the idea of just re-stacking activity after activity. There has to be an easier way to refresh the webview. Please help. :)

like image 705
cdg Avatar asked Apr 01 '10 20:04

cdg


People also ask

How do I refresh a page in WebView?

Android Swipe Down to Refresh a Webview.

How do I refresh my WebView flutter?

To do it move the WebView to StatefulWidget (let's name it WebViewContainer) and pass onWebViewCreated callback to it. Now you are able to reload WebView by calling webViewController. reload() method. Second thing to do is to make reload trigger from outside.

Is Android WebView deprecated?

This interface was deprecated in API level 12. This interface is now obsolete.


2 Answers

You could call an mWebView.reload(); That's what it does

like image 65
Josh Hofing Avatar answered Sep 19 '22 20:09

Josh Hofing


1) In case you want to reload the same URL:

mWebView.loadUrl("http://www.websitehere.php"); 

so the full code would be

newButton.setOnClickListener(new View.OnClickListener() {    public void onClick(View v) {     dgeActivity.this.mWebView.loadUrl("http://www.websitehere.php");    }}); 

2) You can also call mWebView.reload() but be aware this reposts a page if the request was POST, so only works correctly with GET.

like image 29
Pentium10 Avatar answered Sep 22 '22 20:09

Pentium10