Android - WebView back button [duplicate] - android

This question already has answers here:
How to go back to previous page if back button is pressed in WebView?
(18 answers)
Closed 5 years ago.
I have a mirroring of a website in WebView and I would like that when I press the ** Back ** button on the Smartphone, I would go back to the previous page. Currently if I press the ** Back ** button on the Smartphone, the application is minimized (It stays in the background).
I do not know how to do this, can anyone help me?
MainActivity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wv = (WebView) findViewById(R.id.webview1);
wv.loadUrl("https://www.xxxx.com.br");
wv.setWebViewClient(new WebViewClient());
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(false);
Manifest
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#drawable/ic_stat_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Override the onBackPressed method in your activity as below:
#Override
public void onBackPressed(){
WebView wv = (WebView)findViewById(R.id.webview1);
if(wv.canGoBack()){
wv.goBack();
} else {
super.onBackPressed();
}
}
Use the above method inside your class, not outside.
public class MainActivity extends AppCompatActivity {
//onCreate method
//onBackPressed method
//other methods
}

Use this .
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
Add wv as global data
private WebView wv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv = (WebView) findViewById(R.id.webview1);
wv.loadUrl("https://www.xxxxx.com.br");
wv.setWebViewClient(new WebViewClient());
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setSupportZoom(false);
}

Related

Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView= findViewById(R.id.webview);
mywebView.setWebViewClient(new WebViewClient());
mywebView.loadUrl("https://coinvisa.com/");
WebSettings webSettings=mywebView.getSettings();
webSettings.setJavaScriptEnabled(true);
}
public class mywebClient extends WebViewClient{
#Override
public void onPageStarted(WebView view, String url, Bitmap favicon){
super.onPageStarted(view,url,favicon);
}
#Override
public boolean shouldOverrideUrlLoading(WebView view,String url){
view.loadUrl(url);
return true;
}
}
#Override
public void onBackPressed(){
if(mywebView.canGoBack()) {
mywebView.goBack();
}
else{
super.onBackPressed();
}
}enter code here
}
This is the error at end..
Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined
Add param android:exported in AndroidManifest.xml file under activity
Like below code:
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Add android:exported="true" for Launcher activity and android:exported="false" to other activities.
Goto AndroidManifest.xml and add the following line to each activity
<activity
android:name=".MainActivity"
android:exported="true" />

on rotate mobile webview refresh hide menu

i have a problem i am create an app web view to get and website on play store.
the problem is that it have a dropdown Menu html5+jquery+css3. when i rotate the smartphone, the web are refreshed.
this my code Android Studio 3.0:
Activity xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.icarosnet.icarosnetsa.IcarosWeb">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/wv"
/>
</android.support.constraint.ConstraintLayout>
Main.Java
package com.icarosnet.icarosnetsa;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class IcarosWeb extends AppCompatActivity {
WebView wv ;
#Override
public void onBackPressed(){
if(wv.canGoBack()){
wv.goBack();
}else{
super.onBackPressed();
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_icaros_web);
wv= (WebView) findViewById(R.id.wv);
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl("https://icarosnet.com");
wv.setWebViewClient(new WebViewClient());
}
#Override
protected void onSaveInstanceState(Bundle outState ){
super.onSaveInstanceState(outState);
wv= (WebView) findViewById(R.id.wv);
wv.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
super.onRestoreInstanceState(savedInstanceState);
wv= (WebView) findViewById(R.id.wv);
wv.restoreState(savedInstanceState);
}
}
Xml Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.icarosnet.icarosnetsa">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".IcarosWeb">
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
does not respect the content that was loaded by ajax.
how can i prevent refresh and resize the view; or how can i show it only portrait and block the view.
Try this:
It saves state onPause for WebView.
#Override
public void onPause() {
super.onPause();
webViewBundle = new Bundle();
wv.saveState(webViewBundle);
}
Add in OnCreate:
if (webViewBundle == null) {
wv.getSettings().setJavaScriptEnabled(true);
wv.setFocusable(true);
wv.setFocusableInTouchMode(true);
wv.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
wv.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
wv.getSettings().setDomStorageEnabled(true);
wv.getSettings().setDatabaseEnabled(true);
wv.getSettings().setAppCacheEnabled(true);
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv.loadUrl("https://icarosnet.com");
} else {
wv.restoreState(webViewBundle);
}
*Assuming wv would be declared for the class
<activity android:name=".TestActivity"
android:screenOrientation="portrait">
write this line and show it only portrait
You can just add android:screenOrientation = "potrait" inside activity tag in manifest file to make your Activity not rotate to landscape even when phone is rotated.
<activity
android:name="YourActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"/>
#Override
protected void onSaveInstanceState(Bundle outState )
{
super.onSaveInstanceState(outState);
wv.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
wv.restoreState(savedInstanceState);
}
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"><intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

Handling Back Button in Android Webview

I develop an app with WebView and Html5, It works, clicking a link in the webpage goes to the next page in the html file inside my app. But when I click the phone's back button, it give me this error : Unfortunately, APPNAME has stopped. I want to go back to the previous page in the website instead.
The website build with : https://github.com/01org/appframework
MainActivity.java
package com.package.name;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
private WebView WebView;
//Back Button Code
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (WebView.canGoBack()) {
WebView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
//--------------------
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView=(WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(true);
webView.loadUrl("file:///android_asset/index.html");
}
}
Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.package.name.MainActivity">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</android.support.constraint.ConstraintLayout>
AndroidManifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package.name">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
First,
Check if WebView is null.. rename the global variable to webView (private WebView webView;) and in onCreate change WebView webView=(WebView) findViewById(R.id.webview); to webView=(WebView) findViewById(R.id.webview);
You could also try moving the back button handling code to
#Override
public void onBackPressed()
{
....
}
instead of
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
...
}
as in:
#Override
public void onBackPressed()
{
if (webView.canGoBack()) {
webView.goBack();
} else {
super.onBackPressed();
}
}
as mentioned in https://developer.android.com/training/implementing-navigation/temporal.html#back-webviews

Null Object Reference error when adding refresh listener to SwipeRefreshLayout for a WebView [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 2 years ago.
When I add this line of code
swipeLayout.setOnRefreshListener(this);
I get this error
void android.support.v4.widget.SwipeRefreshLayout.setOnRefreshListener
(android.support.v4.widget.SwipeRefreshLayout$OnRefreshListener)'
on a null object reference
MainActivity
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.support.v4.widget.SwipeRefreshLayout;
public class MainActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener {
private WebView mWebView;
private SwipeRefreshLayout swipeLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mWebView = new WebView(this);
mWebView.loadUrl("https://secure.tickspot.com");
mWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
swipeLayout.setOnRefreshListener(this);
}
#Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public void onRefresh() {
mWebView.reload();
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
swipeLayout.setRefreshing(false);
}
}, 1000);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkyong.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="12" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:label="#string/app_name"
android:id="#+id/main_activity"
android:name=".MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Im new to android development and am having trouble understanding the error messages. HELP!
If I'm doing anything else wrong, I would love that feedback too :)
EDIT
I moved the swipe refresh layout code to
layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</android.support.v4.widget.SwipeRefreshLayout>
I had to change
mWebView = new WebView(this);
to
mWebView = (WebView) findViewById(R.id.webView);
And I had to add the following between the SwipeRefreshLayout xml in the main.xml file.
<WebView android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/webView"
android:layout_alignParentTop="true"/>
I have set SwipeRefreshLayout refresh listener into onResume. It worked for me.

WebView with SherlockActionBar reloads on rotation

I know there are a lot of similar questions and believe me, I tried a lot, but nothing worked out for me. I have a Android App which uses a Webview. You can find my App in the Play Store:
https://play.google.com/store/apps/details?id=at.rk.rps&feature=search_result#?t=W251bGwsMSwxLDEsImF0LnJrLnJwcyJd
After a few month in the Play Store I decided to make an update and to use the Android Design Guidelines for my new Design, so a Actionbar was necessary. I went with ActionbarSherlock and everything is fine, except the Webview is now reloading every time I rotate the phone. In my last version I handled this problem with this answer and it worked:
My Webview Reloads When I Change From Portrait To Landscape
But now it won't work again. I have tried that solution too: (I also left a comment at the end of the site)
http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/
With the same disappointing result. I'm not even sure if ActionbarSherlock is the problem, because I've changed a lot, but it is impossible to recreate the old state!
This is what the App looks like (This is only in the new version implemented, you can't find it in the version which is publish on the Play Store):
Here's a part of my code, first the manifest, then the layout and afterwards the java code:
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="at.rk.rps"
android:versionCode="8"
android:versionName="0.4" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:icon="#drawable/rps"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light.DarkActionBar" >
<activity
android:name=".RPSActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SettingsActivity"
android:label="#string/app_name"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name=".DonateActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".PayPalActivity"
android:configChanges="orientation"
android:label="#string/app_name" >
</activity>
<activity
android:name=".LoadingScreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/paypal_loadingtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:gravity="center"
android:text="#string/paypal_loadingtext"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/rk_red" />
<ProgressBar
android:id="#+id/paypal_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/paypal_loadingtext"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="10dp" />
<WebView
android:id="#+id/paypal_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:visibility="gone" />
</RelativeLayout>
Java code:
package at.rk.rps;
import org.apache.http.util.EncodingUtils;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
public class PayPalActivity extends SherlockActivity {
private ActionBar actionbar;
private WebView webview;
private TextView loadingtxt;
private ProgressBar progressbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getSharedPreferences(RPSActivity.PREFS_NAME, 0).getBoolean(RPSActivity.FULLSCREEN, true)) this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.paypal);
initUI();
}
private void initUI() {
actionbar = getSupportActionBar();
actionbar.setTitle(R.string.paypal_actionbar_headline);
actionbar.setHomeButtonEnabled(true);
this.actionbar.setDisplayHomeAsUpEnabled(true);
loadingtxt = (TextView) findViewById(R.id.paypal_loadingtext);
progressbar = (ProgressBar) findViewById(R.id.paypal_progressbar);
webview = (WebView) findViewById(R.id.paypal_webview);
webview.requestFocus(View.FOCUS_DOWN); // Enables the keyboard in landscape mode
webview.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_UP:
if (!v.hasFocus()) {
v.requestFocus();
}
break;
}
return false;
}
});
webview.getSettings().setJavaScriptEnabled(true); // Enables JavaScript
webview.getSettings().setBuiltInZoomControls(true); // Enables zoom
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // Displays scrollbars outside the view
webview.setScrollbarFadingEnabled(false);
webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
loadingtxt.setVisibility(TextView.VISIBLE);
progressbar.setVisibility(ProgressBar.VISIBLE);
webview.setVisibility(WebView.GONE);
progressbar.setProgress(progress);
if(progress == 100) {
loadingtxt.setVisibility(LinearLayout.GONE);
progressbar.setVisibility(LinearLayout.GONE);
webview.setVisibility(WebView.VISIBLE);
}
}
});
webview.setWebViewClient(new WebViewClient());
byte[] post = EncodingUtils.getBytes("cmd=_s-xclick&hosted_button_id=VRM63MEY4J936", "BASE64");
webview.postUrl("https://www.paypal.com/cgi-bin/webscr", post);
}
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
#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);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater i = getSupportMenuInflater();
i.inflate(R.menu.paypal_menu, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case android.R.id.home:
finish();
return(true);
case R.id.paypal_actionbar_reload:
webview.reload();
return(true);
default:
return super.onOptionsItemSelected(item);
}
}
}
I found the answer here:
https://stackoverflow.com/a/9550231/1254514
"Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation."
So I had to do the following:
Add in your Android manifest to the activity you like:
android:configChanges="keyboardHidden|orientation|screenSize"
Then override the function in your activity:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
Maybe if you try something like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getSharedPreferences(RPSActivity.PREFS_NAME, 0).getBoolean(RPSActivity.FULLSCREEN, true)) this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.paypal);
initUI();
if(savedInstanceState != null)
{
/** Restoring the web Ui state. */
webView.restoreState(savedInstanceState);
}
}
#Override
public void onSaveInstanceState(Bundle outState)
{
/** Saving the webview state. */
webView.saveState(outState);
}
This is untested but it seems like you are not saving the state of the webview. I am using this code in a Fragment and it seems to save the state of the webview.

Categories

Resources