I am facing problem in building android webview . The problem is that when the app is running and phone change direction , i mean from horizontal to vertical or vice versa the app get restarted. Thanks
6 Answers
The default behavior is to restart the activity when the screen orientation changes. You can write custom code to handle orientation change events yourself though:
- Add
android:configChanges="orientation"
to yourAndroidManifest.xml
- Override
onConfigurationChanged
from your activity

- 59,111
- 13
- 86
- 103
-
Thanks to all.Its get solved but now what i am facing is that when it change direction i get a white blank page, alhtough i have enabled javascript and other settings . Thanks – umar Feb 28 '11 at 16:04
The default android behaviour is to destroy and recreate the activity on orientation change. You can either override onSaveInstanceState()
to save your application data before destroy, or you can call onRetainNonConfigurationInstance()
to keep hold of a stateful object. See the android docs.

- 247
- 2
- 11
Umar,
You will want to add the android:configChanges="orientation"
parameter to your Activity
in your AndroidManifest.xml
to prevent your activity from restarting on orientation change.
See: http://developer.android.com/guide/topics/manifest/activity-element.html#config

- 33,439
- 9
- 77
- 71
Another possibility (usually a decent fit for lighter Activities that don't have state outside a WebView, for instance) is to absorb the rotation event and let the view redraw itself. See http://www.androidguys.com/2008/11/11/rotational-forces-part-three/ - the idea is:
Put an android:configChanges entry in your file, listing the configuration changes you want to handle yourself versus allowing Android to handle for you.
Implement onConfigurationChanged() in your Activity, which will be called when one of the configuration changes you listed in android:configChanges occurs

- 37,905
- 5
- 60
- 62
-
Thanks to all.Its get solved but now what i am facing is that when it change direction i get a white blank page, alhtough i have enabled javascript and other settings . Thanks – umar Feb 28 '11 at 16:04
-
It might help if you post your source in your question above, then. – Yoni Samlan Feb 28 '11 at 18:24
umar... Saving instance state is quite different on the Android. On a soft kill (phone rotation) you may save your non view state in onSaveInstanceState using bundles. On a hard kill (back button while activity has focus) you may elect to save your non view and view state in onStop perhaps using preferences. You can restore your state in onCreate.
You can leverage the fact that IF onSaveInstanceState is called it will be called BEFORE onStop. So this lets you set a flag isSavedInstanceState to true in onSaveInstanceState to avoid saving prefs in onStop except on a hard kill. The trick is to reset the flag isSavedInstanceState to false in onResume NOT in onCreate.
JAL
I have sample code here.

- 3,319
- 2
- 20
- 17