0

I am doing a project using android studio. I have converted my website into an android application. In my android application when I change my android mobile's orientation from vertical to horizontal mode, my application gets reloaded from the first page.

The android application code is given below.

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.example.nandha.firstproject.MainActivity">

    <WebView
        android:id="@+id/myWebView"
        android:layout_width="368dp"
        android:layout_height="495dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp" />

</android.support.constraint.ConstraintLayout>

MainActivity.java

package com.example.nandha.firstproject;

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 {
    private WebView myWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myWebView = (WebView) findViewById(R.id.myWebView);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        myWebView.loadUrl("http://192.168.43.75/login.php");
        myWebView.setWebViewClient(new WebViewClient());
    }

    @Override
    public void onBackPressed() {
        if (myWebView.canGoBack()) {
            myWebView.goBack();
        } else {
            super.onBackPressed();
        }
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nandha.firstproject">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>

    <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 page of my application

enter image description here

When I change my orientation to horizontal mode it gets reloaded as shown below from the first page

3rd page

Now, I need only the page in horizontal mode for which I changed to horizontal orientation and not from the previous page. my problem is I change the orientation to horizontal mode only for 2nd page. But, my application gets reloaded from 1st page in horizontal orientation

Kindly help me to fix this problem.

nandha kumar
  • 303
  • 3
  • 8
  • Try this for not reload when change orientation: [http://stackoverflow.com/a/12131069/5675636](http://stackoverflow.com/a/12131069/5675636) – Carmen May 18 '17 at 17:49
  • Actually the page gets reloaded automatically when I change the orientation to landscape. How to fix it? – nandha kumar May 19 '17 at 04:46

0 Answers0