Hi,

I'm working in a fragment based app. It has only 1 activity. The activity 
is used as frame and for the ActionBar etc. The different screens are 
implemented as fragments.

We are using a combination of setRetainInstance(true), to preserve the 
state of the fragment (e.g. data which was already downloaded from web 
service), and recreate the views normally in onCreateView(), in order to 
use different layout for phone and tablet.

Ok, works great! App is finished. But we have a WebView form.

Now when the device is rotated, and onCreateView() is called, the data 
which was entered in the form disappears. I have to fix this.

Possible solutions:

1. I found is possible to read and write the input fields using javascript. 
This is not usable for us, since WebView content can change and we don't 
can be certain about which inputs are there, which ids, etc.

2. Hold the WebView as an instance variable of the fragment - since the 
fragment is not recreated, thanks to setRetainInstance(true), I would 
expect it still "holds" the inputs. In onCreateView I check if the variable 
is null, If yes create / inflate it, then always add it as child of 
container FrameLayout from XML. Well, it doesn't help. With this also the 
inputs are lost on orientation change.

3. Declare configChanges="orientation" in the manifest. But this is also 
very bad, because it affects the activity and thus all our app. I would 
have to implement onConfigurationChanged in my fragments and emulating 
there what's currently being done by onCreateView() - recreate the views, 
restore state in views, etc.


So well, I have 3 solutions, 1. Not usable, 2. Doesn't work, 3. Don't know 
how to do it / it's probably a mess and don't want to break my code base.


But I have to do it cause it's super-important for managers that 
the WebView retains the inputs and I think they don't care if I have to 
mess up the whole app because of that. 

Any ideas? Thanks.


 

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to