简体   繁体   English

在Webview活动之间切换而无需重新加载页面

[英]switching between webview activity without reloading the page

Here is i wish to do. 这是我想做的。 I want to have multiple webview loading their own page. 我想让多个Webview加载自己的页面。 Those webviews are created in different activies that are resulted from item click on a listview. 这些Web视图是在不同的活动中创建的,这些活动是通过单击列表视图中的项目而产生的。

Sometimes i want to switch from one webview activity to another. 有时我想从一个webview活动切换到另一个。

What i have attempted shows that switching between those activities always called onCreate() method that calls webView.loadUrl(). 我所尝试的结果表明,在这些活动之间进行切换总是调用调用webView.loadUrl()的onCreate()方法。 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. 关键是如何在不重新加载内部webView的情况下切换到现有活动。 Thank you for advances 谢谢你的进步

If you create an activity for each webView there is no possibility to do what you describe. 如果为每个webView创建一个活动,则无法执行您描述的操作。 this happens since you close each activity and give an "OK" to the GC to collect it and throw all WebView data. 之所以会发生这种情况,是因为您关闭了每个活动,并向GC授予了“确定”以收集该活动并抛出所有WebView数据。

  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). 您需要做的是创建某种类型的Web容器,该容器将容纳预定义数量的WebView(存活的时间不超过6个,它将耗尽设备的内存)。
  2. Whenever you press your list item, start loading a WebView in your container, and make it visible on top of your current Layout. 每当您按下列表项时,就开始在容器中加载WebView,并使它在当前布局的顶部可见。
  3. When you press back, just set visibility of the web container to GONE. 按下时,只需将Web容器的可见性设置为GONE。
  4. If you try to open a 7th WebView, just kill the first one, and continue. 如果您尝试打开第7个WebView,只需杀死第一个,然后继续。
  5. This method will assure you that you have live WebViews that do not need to be loaded again... 此方法将确保您拥有不需要再次加载的实时WebView。

Hope this helps. 希望这可以帮助。

You can do this with a ViewAnimator . 您可以使用ViewAnimator进行此操作 Create your WebViews and add them to the ViewAnimator with (something like) 创建您的WebView并将其添加到ViewAnimator中(类似)

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) 然后按索引切换到特定的WebView(类似)

mViewAnimator.setDisplayedChild(index_0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM