M Rijalul Kahfi
M Rijalul Kahfi

Reputation: 1490

switching between webview activity without reloading the page

Here is i wish to do. I want to have multiple webview loading their own page. Those webviews are created in different activies that are resulted from item click on a listview.

Sometimes i want to switch from one webview activity to another.

What i have attempted shows that switching between those activities always called onCreate() method that calls webView.loadUrl(). Therefore, the web page get reloaded everytime i switch.

Anyone have idea to design such activities navigation? The key is how to switch to an existing activity without reloading the webView inside. Thank you for advances

Upvotes: 1

Views: 2000

Answers (2)

Torid
Torid

Reputation: 4196

You can do this with a ViewAnimator. Create your WebViews and add them to the ViewAnimator with (something like)

mViewAnimator.addView(mWebView0, index_0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,                                   ViewGroup.LayoutParams.FILL_PARENT));

then switch to a particular WebView by index (something like)

mViewAnimator.setDisplayedChild(index_0);

Upvotes: 0

Rotemmiz
Rotemmiz

Reputation: 7971

If you create an activity for each webView there is no possibility to do what you describe. this happens since you close each activity and give an "OK" to the GC to collect it and throw all WebView data.

  1. What you need to do is to create some kind of a web container that will hold a predefined amount of WebViews (don't keep more than ~6 alive, it will eat up you device's memory).
  2. Whenever you press your list item, start loading a WebView in your container, and make it visible on top of your current Layout.
  3. When you press back, just set visibility of the web container to GONE.
  4. If you try to open a 7th WebView, just kill the first one, and continue.
  5. This method will assure you that you have live WebViews that do not need to be loaded again...

Hope this helps.

Upvotes: 1

Related Questions