-2

Is there a way to stop this? I have tried the following:

//Adding this to the Manifest for the activity:
android:configChanges="orientation"

and

//Adding this to the MainActivity
@Override
    public void onConfigurationChanged(Configuration newConfig){        
        super.onConfigurationChanged(newConfig);
    }

It doesn't work though so any ideas?

Tim
  • 1,056
  • 4
  • 17
  • 34
  • I haven't heard of PhoneGap... Would I have to rewrite my current system for it? As that's why I wanna just show a site - not much reprogramming! – Tim Aug 23 '12 at 20:42
  • I don't know anything about your current system. Can you provide more details on what you're trying to do, and what's happening? – xdumaine Aug 23 '12 at 20:43
  • Well my question still stands - how can I stop the site auto-loading the initial page instead of rotating the page it's on? :p – Tim Aug 23 '12 at 20:45
  • Tim, what "initial page" are you talking about? You're not being very descriptive. Is it a web application? Is it navigating to a new URL? – xdumaine Aug 23 '12 at 20:47
  • Its a website being displayed in a WebView. – Tim Aug 23 '12 at 20:47

2 Answers2

1

this is just a suggestion but you can try it :-)

  android:configChanges="keyboardHidden|orientation"

I use this but not in combination with a webview. But it stops building the activity new in every case I testet with my activitys.

JackTools.Net
  • 734
  • 6
  • 13
0

Orientation change actually restart the whole activity. It mean that onDestroy() is called, then onCreate() is called again...

It is done by design, because the activity will eventually need to load a different layout, different configurations, and so on...

You should save the activity state using the onSaveInstanceState() method, and reusing the Bundle object passed as a parameter to the onCreate() method.

Read http://developer.android.com/guide/topics/resources/runtime-changes.html which explains all this process (and optional additional optimisations)

Orabîg
  • 11,718
  • 6
  • 38
  • 58
  • How would this be coded? As an if-statement based on if the screen is rotated? – Tim Aug 23 '12 at 20:52
  • Well, no. You should store any useful informations about your context in the Bundle object in your `onSaveInstaceState()` method. Then your `onCreate()` method must use these informations to build the previous state of your screen – Orabîg Aug 23 '12 at 21:58
  • But how is a Bundle saved (as in, how and when is the onSaveInstanceState() called)? – Tim Aug 23 '12 at 22:16
  • You just have to store informations in the Bundle object, in that method, and the system does the rest. See an implementation example at http://stackoverflow.com/questions/151777/saving-activity-state-in-android. – Orabîg Aug 23 '12 at 22:24
  • Okay - I see how to do this - but how do I retain the web page? onSaveInstanceState.put......? – Tim Aug 23 '12 at 22:30