webview resetting to index.html when changing orientation

by h...@nnes » Sun, 08 Mar 2009 21:07:50 GMT


Sponsored Links
 Hi all,

I'm trying to get some website as a fullscreen webapp going; using
webview.

So I have a simple CSS layout based on percental width and height to
fill the entire screen on either portrait and landscape.

All is doing fine apart that when I'm navigating away from my
index.html (lets say to index01.html) and doing a orientation change
by opening or closing the keyboard on the G1, the entire page flips
back to index.html.

No idea what's the reason for this and I couldn't find any ressources.
So any help would be highly appreciated.

Thanks a lot, Best, h...@nnes


This is my simple fullscreen code:


 public void onCreate(Bundle icicle) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags
(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);

        super.onCreate(icicle);
        try{
            WebView wv = new WebView(this);
            wv.getSettings().setJavaScriptEnabled(true);
            wv.getSettings().setJavaScriptCanOpenWindowsAutomatically
(false);
            wv.getSettings().setPluginsEnabled(true);
            wv.getSettings().setSupportMultipleWindows(false);
            wv.getSettings().setSupportZoom(false);
            wv.setVerticalScrollBarEnabled(false);
            wv.setHorizontalScrollBarEnabled(false);
            wv.loadUrl(" http://www.myserver.com/index.html" ;);
            WebViewClient wvc = new WebViewClient();
            wvc.shouldOverrideUrlLoading(wv, " http://www.myserver.com/ 
index.html");
            wv.getSettings().setLoadsImagesAutomatically(true);
            wv.setWebViewClient(wvc);
            setContentView(wv);

--~--~---------~--~----~------------~-------~--~----~



webview resetting to index.html when changing orientation

by Mark Murphy » Sun, 08 Mar 2009 21:12:38 GMT


 


This is expected behavior and has little to do with WebView. By default,
when the screen is rotated, your activity is destroyed and restarted. If
you want to maintain state as the rotation occurs, or otherwise control
how rotation behaves, you will need to add some code.

I have a five-post series on AndroidGuys that covers various
possibilities with respect to handling rotation events:

 http://androidguys.com/?s=rotational +forces

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android Training in Sweden --  http://www.sotrium.com/training.php 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


webview resetting to index.html when changing orientation

by h...@nnes » Mon, 09 Mar 2009 00:54:20 GMT


 Hi Mark, You saved me another time, I remember! Thanks you I really
appreciate that.

I'll check your series. Thanks again, Best, Hannes








--~--~---------~--~----~------------~-------~--~----~



webview resetting to index.html when changing orientation

by h...@nnes » Mon, 09 Mar 2009 00:57:43 GMT


 Those  http://www.androidguys.com/ are quite troublesome to reach from 
Germany. They're down AGAIN or there is some IP country specific
issue. I also rember that from your last post. Best, Hannes





--~--~---------~--~----~------------~-------~--~----~



webview resetting to index.html when changing orientation

by Mark Murphy » Mon, 09 Mar 2009 01:07:27 GMT


 


It may just be routing or traffic issues to Europe. They're definitely
running.

If you search:

rotational forces android

in Google, you can get to the cached copies, or to some sites that
ripped off the posts.

FWIW, that same material is in my Android book.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Compass still crashing.

I've modified the code a bit since the last time, and now it crashes
at runtime.
I've got the log-cat and code below.
Any suggestions, or links to a tutoiral on how to go about debugging
would be appreciated.
Thanks,
Declan

package com.wissen.android;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.{*filter*};
import android.util.Config;
import android.util.Log;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ZoomControls;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class Hello extends MapActivity implements LocationListener {
        /** Called when the activity is first created. */

        EditText                txted                   = null;
        Button                  btnSimple               = null;
        MapView                 gMapView                = null;
        MapController   mc                              = null;
        Drawable                defaultMarker   = null;
        GeoPoint                p                               = null;
        double                  latitude                = 0.0, longitude = 0.0; 
// for current location
        double                  desLat, desLong;// for current destination
        private SensorManager mSensorManager;
    private float[] mValues;
    private static final String TAG = "Compass";
    // for compasse

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                // makes the field with text
                txted = (EditText) findViewById(R.id.id1);
                String currentLocation = "Lat: " + latitude + " Lng: " + 
longitude;
                txted.setText(currentLocation);
                // Creating and initializing Map
                gMapView = (MapView) findViewById(R.id.myGMap);
                p = new GeoPoint((int) (latitude * 1000000), (int) (longitude *
1000000));
                gMapView.setSatellite(true);
                mc = gMapView.getController();
                mc.setCenter(p);
                mc.setZoom(14);

                /** Add a location mark**/
                MyLocationOverlay myLocationOverlay = new MyLocationOverlay();
                List<Overlay> list = gMapView.getOverlays();
                list.add(myLocationOverlay);

                // Adding zoom controls to Map
                ZoomControls zoomControls = (ZoomControls) 
gMapView.getZoomControls
();
                zoomControls.setLayoutParams(new ViewGroup.LayoutParams
(LayoutParams.WRAP_CONTENT,
                                LayoutParams.WRAP_CONTENT));

                gMapView.addView(zoomControls);
                gMapView.displayZoomControls(true);

                // Getting locationManager and reflecting changes over map if
distance travel by
                // user is greater than 500m from current location.
                LocationManager lm = (LocationManager) getSystemService
(Context.LOCATION_SERVICE);
                lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,
500.0f, this);

        }
        public void onSensorChanged(int sensor, float[] values) {
        if (Config.LOGD) Log.d(TAG, "sensorChanged (" + values[0] + ",
" + values[1] + ", " + values[2] + ")");{
                mValues = values;
                //Doesn't work, should appear if this section is called,
never called?
                String currentLocation = "Got magnetic
==================================";

                txted.setText(currentLocation);

                int i=90;
                if (mValues != null) {
                                if(mValues[0]<i+3&mValues[0]>i-3)
                        {
                                        {*filter*} {*filter*} = 
({*filter*})getSystemService
(Context.{*filter*}_SERVICE);
                                        {*filter*}.vibrate((long) 300.0);
                        }
                        }
                        //Code needed to make a compasse vibrate, I should be 
from baring
methad

{*filter*} {*filter*} = ({*filter*})getSystemService
(Context.{*filter*}_SERVICE);
{*filter*}.vibrate((long) 300.0);

        }
    }
        /* This method is called when use position will get changed */
        public void onLocationChanged(Location location) {
                if (location != null) {
                        double lat = location.getLatitude();
                        double lng = location.getLongitude();
                        String currentLocation = "Lat: " + lat + " Lng: " + lng;
                        txted.setText(currentLocation);
                        p = new GeoPoint((int) lat * 1000000, (int) lng * 
1000000);
                        mc.animateTo(p);
                        {*filter*} {*filter*} = ({*filter*})getSystemService
(Context.{*filter*}_SERVICE);
                        {*filter*}.vibrate((long) 300.0);
                }
        }

        public void onProviderDisabled(String provider) {
                // required for interface, not used
        }

        public void onProviderEnabled(String provider) {
                // required for interface, not used
        }

        public void onStatusChanged(String provider, int status, Bundle
extras) {
                // required for interface, not used
        }

        protected boolean isRouteDisplayed() {
                // TODO Auto-generated method stub
                return false;
        }

        /* User can zoom in/out using keys provided on keypad*/
        public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_I) {
                        
gMapView.getController().setZoom(gMapView.getZoomLevel() + 1);
                        return true;
                } else if (keyCode == KeyEvent.KEYCODE_O) {
                        
gMapView.getController().setZoom(gMapView.getZoomLevel() - 1);
                        return true;
                } else if (keyCode == KeyEvent.KEYCODE_S) {
                        gMapView.setSatellite(true);
                        return true;
                } else if (keyCode == KeyEvent.KEYCODE_T) {
                        gMapView.setTraffic(true);
                        return true;
                }
                return false;
        }

        /* Class overload draw method which actually plot a marker,text etc.
on Map */
        protected class MyLocationOverlay extends
com.google.android.maps.Overlay {

                @Override
                public boolean draw(Canvas canvas, MapView mapView, boolean 
shadow,
long when) {
                        Paint paint = new Paint();

                        super.draw(canvas, mapView, shadow);
                        // Converts lat/lng-Point to OUR coordinates on the 
screen.
                        Point myScreenCoords = new Point();
                        mapView.getProjection().toPixels(p, myScreenCoords);

                        paint.setStrokeWidth(1);
                        paint.setARGB(255, 255, 255, 255);
                        paint.setStyle(Paint.Style.STROKE);

                        Bitmap bmp = 
BitmapFactory.decodeResource(getResources(),
R.drawable.marker);

                        canvas.drawBitmap(bmp, myScreenCoords.x, 
myScreenCoords.y, paint);
                        canvas.drawText("I am here...", myScreenCoords.x, 
myScreenCoords.y,
paint);
                        return true;
                }
        }
}




08-12 15:39:02.892: ERROR/AndroidRuntime(548): Uncaught handler:
thread main exiting due to uncaught exception
08-12 15:39:02.912: ERROR/AndroidRuntime(548):
java.lang.RuntimeException: Unable to start activity ComponentInfo
{com.example.North/com.example.North.North}:
java.lang.ClassCastException: com.example.North.North
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2268)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.os.Handler.dispatchMessage(Handler.java:99)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.os.Looper.loop(Looper.java:123)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread.main(ActivityThread.java:3948)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
java.lang.reflect.Method.invokeNative(Native Method)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
java.lang.reflect.Method.invoke(Method.java:521)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
dalvik.system.NativeStart.main(Native Method)
08-12 15:39:02.912: ERROR/AndroidRuntime(548): Caused by:
java.lang.ClassCastException: com.example.North.North
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
com.example.North.North.onCreate(North.java:61)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
08-12 15:39:02.912: ERROR/AndroidRuntime(548):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2231)
--~--~---------~--~----~------------~-------~--~----~

2. ScrollView disappears when the keyboard appears on the screen

I have the following layout:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                android:orientation="vertical" 
android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <TextView android:id="@+id/title" android:text="@string/
main_updateStatus"
                        android:textStyle="bold" android:padding="2dip"
android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />

                <TextView android:id="@+id/advanced" android:text="@string/
link_advanced"
                        android:textStyle="bold" android:textSize="12sp"
android:padding="4dip"
                        android:clickable="true" 
android:layout_width="wrap_content"
                        android:layout_height="wrap_content" 
android:layout_toRightOf="@id/
title"
                        android:textColor="@color/blue_link" />
        </RelativeLayout>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                android:orientation="vertical" 
android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <TextView android:id="@+id/photo" 
android:text="@string/link_photo"
                        android:textStyle="bold" android:textSize="12sp"
android:padding="4dip"
                        android:clickable="true" 
android:layout_width="wrap_content"
                        android:layout_height="wrap_content" 
android:textColor="@color/
blue_link" />
        </RelativeLayout>

        <ScrollView android:layout_marginBottom="180dip" android:id="@+id/
ScrollView01"
                android:layout_height="wrap_content"
android:layout_width="fill_parent"
                >
                <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                        android:orientation="vertical" 
android:layout_width="fill_parent"
                        android:layout_height="wrap_content">
                        <EditText android:id="@+id/updateStatus" 
android:padding="3dip"
                                android:scrollHorizontally="true"
android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                 />

                        <TextView android:id="@+id/titleLabel" 
android:text="@string/
label_titleField"
                                android:layout_width="wrap_content"
android:layout_height="wrap_content"
                                android:visibility="gone" />

                        <EditText android:id="@+id/titleField" 
android:padding="3dip"
                                android:scrollHorizontally="true"
android:layout_width="fill_parent"
                                android:layout_height="wrap_content" 
android:visibility="gone" />

                        <RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/
android"
                                android:orientation="vertical" 
android:layout_width="wrap_content"
                                android:layout_height="wrap_content">

                                <Button android:id="@+id/updateStatusButton" 
android:text="@string/
button_updateStatus"
                                        android:layout_width="wrap_content"
android:layout_height="wrap_content" />

                                <Button android:id="@+id/removePhotoButton" 
android:text="@string/
button_removePhoto"
                                        android:layout_width="wrap_content"
android:layout_height="wrap_content"
                                        
android:layout_toRightOf="@id/updateStatusButton"
                                        android:visibility="gone" />
                        </RelativeLayout>

                        <ImageView android:id="@+id/my_image"
android:layout_width="wrap_content"
                                android:layout_height="wrap_content" 
android:scaleType="fitCenter"
                                android:layout_gravity="center_horizontal" />

                        <!--
                                android:layout_marginTop="2px" 
android:layout_marginBottom="2px"
                        -->
                </LinearLayout>

        </ScrollView>

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                android:orientation="vertical" 
android:layout_width="fill_parent"
                android:layout_height="wrap_content"
android:layout_marginTop="-180dip"
                >
                <TextView android:id="@+id/history" android:text="@string/
title_history"
                        android:textStyle="bold" 
android:layout_width="fill_parent"
                        android:layout_height="wrap_content" 
android:background="#000000"
                        android:textColor="#FFFFFF"
                        />

                <ListView android:id="@+id/myListView"
android:layout_width="fill_parent"
                        android:layout_height="wrap_content" />
        </LinearLayout>

</LinearLayout>

When I click on the EditText "@+id/updateStatus" of the ScrollView,
the keyboard appears on the screen of the device and the ScrollView is
hidden. I'd prefer to hide the ListView "@+id/myListView" at the end.

Is it possible? Why that view is hidden?

Thanks
Emanuele
--~--~---------~--~----~------------~-------~--~----~

3. SCTP support on Android

4. When launch browser, can you set http header?

5. How to use Thread with SurfaceView, ie draw in a separate thread?

6. Sync Account "non_syncable"

7. Switching Content Providers for the same Content URI