请问的WebView saveState和()preserve JavaScript变量/环境? [英] Does WebView saveState() preserve Javascript variables/environment?

查看:181
本文介绍了请问的WebView saveState和()preserve JavaScript变量/环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜查多个线程,但仍无法找到答案,我的问题。我工作的一个安卓应用程序,它使用了的WebView

I've searched many threads and still cannot find the answer to my question. I'm working on an Android app which uses WebView.

我用的onSaveInstanceState() onRestoreInstanceState()保存的WebView 状态是这样的:

I use onSaveInstanceState() and onRestoreInstanceState() to save the WebView state like this:

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    webView.saveState(savedInstanceState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    webView.restoreState(savedInstanceState);
}

我也有这样的我的onCreate()

public void onCreate(Bundle savedInstanceState) {
    ... other code ...
    if(savedInstanceState != null){
        webView.saveState(savedInstanceState);
    }else{
        webView.loadUrl("http://mypage");
    }
}

的问题:似乎恢复的WebView 不恢复 Javascript的变量/环境/工作空间都没有。当应用程序被杀害的背景,然后还原,整个JavaScript是用了所有的对象/变量。 JavaScript的code是命名空间的,即 window.utilitiesPack window.eventHandlers window.automation 等,他们是不确定的。此外 JQuery的和其他JavaScript插件被使用:所有的人似乎后是不确定的恢复状态。基本上整个JavaScript是不会恢复。

The problem: It seems that restoring WebView does not restore the Javascript variables/environment/workspace at all. When app is killed in the background and then restored, the whole Javascript is gone with all the objects/variables. The javascript code is name-spaced, i.e. window.utilitiesPack, window.eventHandlers, window.automation, etc and they are undefined. Also JQuery and other javascript plugins are used: all of them seem to be undefined after restore state. Basically the whole Javascript is not restored.

有人可以证实或否定,这是真的怎么(JavaScript的不保存)?如果整个工作区的Javascript不保存,那么究竟是什么 WebView.saveState()保存?有一些简单/优雅的方式来利用现有的API,以preserve的Javascript对象?

Can someone confirm or disprove that this is how it really is (Javascript not saved)? If the whole Javascript workspace is not saved, then what exactly does WebView.saveState() save? Is there some easy/elegant way to use existing API to preserve the Javascript objects?

// ============================================= =========

//======================================================

UPDATE1:所以,问题依然存在。最显著困难是这样的:

Update1: So the problem remains. The most significant difficulty is this:

我推出一个摄像机意图的结果。拍摄照片时,应用程序得到回的WebView 活动,应该使用JavaScript来更新HTML5 的localStorage 有一些数据变量。

I am launching a Camera Intent for a result. When picture is taken, app gets back to WebView activity and is supposed to use Javascript to update HTML5 LocalStorage with some data variables.

的WebView 在显示相机的活动就会被杀死,所以当我们回来的WebView,没有使用Javascript了,也没有功能,我可以从Android的调用的主要活动code。这发生在银河S3 每一次。它仍然发生在其他的手机,但承担的画面不是每一次。

The main Activity with WebView gets killed while Camera Activity is displayed, so when we come back to WebView, there is no Javascript anymore and no functions I can call from Android code. This happens every single time on Galaxy S3. It still happens on other phones, but not every time on picture taking.

不知道这里做什么。不知怎的,我必须做的主要活动与WebView功能保留,而图像正在用相机拍摄意图的状态。有没有人有一个想法如何能做到这一点?

Don't know what to do here. Somehow I must make the main Activity with WebView to retain the state while the picture is being taken with the Camera Intent. Does anyone have an idea how this can be achieved?

推荐答案

很少的信息发现,仅这行:

Very few information found, only this line:

Please note that this method no longer stores the display data for this WebView. The previous behavior could potentially leak files if restoreState(Bundle) was never called.

和这一行:

Returns the same copy of the back/forward list used to save the state.

在<一href="http://developer.android.com/reference/android/webkit/WebView.html#saveState(android.os.Bundle)" rel="nofollow">http://developer.android.com/reference/android/webkit/WebView.html#saveState(android.os.Bundle)"

这篇关于请问的WebView saveState和()preserve JavaScript变量/环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆