Currently XWalkView doesn’t support reusing across multiple activities because 
internally it will listen to activity’s status change and then handle 
show/hide/pause/resume/destroy automatically.
So when the activity is destroyed, the XWalkView embedded in the activity will 
also be destroyed.
We are working on this, please stay tune.
Also, there’s a similar issue reported in our JIRA: 
https://crosswalk-project.org/jira/browse/XWALK-4730
You may want to watch this for the progress.

From: Crosswalk-help 
[mailto:[email protected]] On Behalf Of Zubkjv
Sent: Thursday, September 10, 2015 5:24 PM
To: [email protected]
Subject: [Crosswalk-help] Reuse XWalkView when activity is recreated

Hi all,

I'm using the embedded Android SDK in our application. Everything is working 
fine, except when we have a new activity due to a rotation change.

First I tried to work with the methods saveState and restoreState by retaining 
the bundle given by this methods. The page is reloaded, but not the whole state 
(executed JS-methods for instance in a single page application). I have the 
feeling that the url is just reloaded.

Secondly I tried to retain the view itself through activities. The first time 
the page is rendered well. After activity recreation the view is gone. With a 
normal WebView this way of working is working well. Why it isn't working with 
Crosswalk?

Here is the sample code for crosswalk:
public class MainActivity extends Activity {

    private static XWalkView crosswalk;
    private static boolean newView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        newView = false;
        if (crosswalk == null) {
            crosswalk = new XWalkView(this);
            newView = true;
        }

        ViewGroup viewGroup = (ViewGroup) findViewById(R.id.test);
        if (!newView) {
            ((ViewGroup)crosswalk.getParent()).removeView(crosswalk);
        }

        viewGroup.addView(crosswalk);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (newView) {
            crosswalk.load("http://www.google.be<http://www.google.be/>", null);
        }
    }
}

Below you can find the working version for the default WebView:
public class WebViewActivity extends Activity {
    private static WebView webview;
    private static boolean newView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        newView = false;
        if (webview == null) {
            webview = new WebView(this);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setDomStorageEnabled(true);
            newView = true;
        }

        ViewGroup viewGroup = (ViewGroup) findViewById(R.id.test);
        if (!newView) {
            ((ViewGroup)webview.getParent()).removeView(webview);
        }

        viewGroup.addView(webview);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (newView) {
            webview.loadUrl("http://www.google.be<http://www.google.be/>");
        }
    }
}

Thanks,
Kind regards,
Jo

_______________________________________________
Crosswalk-help mailing list
[email protected]
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help

Reply via email to