3

How can I retain text-selected find status when screen rotation in android

In my Application, I use Webview to show the website, then I long press the website content, to create the system default Actionmode,the "select" ,"copy" ,"share" ,"find" menu show, then I click the "find" item the selected word can be saw in find text editor. But when I rotate the screen, all the menu and find text editor is destroyed, return to the initial status when I open the website at beginning. My question is after screen rotation ,what can I do to retain the find status?

PS: I know when the screen rotating, the Activity is destroyed and recreated, so the status before rotating lost. But I do not know what object should I save in onSaveIntanceState() method. Also I do not want to use the android:configChanges in AndroidManifest.xml file.

I did like below

protected void onSaveInstanceState(Bundle outState) {
    webView.saveState(outState);
}

Then recover this in your onCreate after the webview has been re-inflated of course:

public void onCreate(final Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.blah);
   if (savedInstanceState != null)
      ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}

but it does not work, the text-selected-find status is still lost.

I think if I can get the system default ActionMode instance,so I can save it, but I don't find any way to get that instance.

Kumar V
  • 8,669
  • 8
  • 37
  • 55
user2614801
  • 105
  • 5

1 Answers1

0

Try this solution. I think you will get a good idea on how to use onSaveInstanceState() method.

EDIT: Put it as below

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}

You need to put these two methods in your class and override them. Also, you did not put super constructor, which is important.

Community
  • 1
  • 1
  • But in onSaveInstanceState(),**what Object should I save**,can you explain something more – user2614801 Aug 31 '13 at 07:34
  • You can save the Bundle object from `onCreate(Bundle savedInstanceState)`. –  Aug 31 '13 at 07:39
  • Check the EDIT part of my answer and also try to implement the `Parcelable` class as shown at the link I shared. –  Aug 31 '13 at 14:47