public class XWalkInitializer
extends java.lang.Object
XWalkInitializer is an alternative to XWalkActivity with the difference
that it provides a way to initialize the Crosswalk runtime in background silently. Another
advantage is that the developer can use their own activity class directly rather than having it
extend XWalkActivity. However, XWalkActivity is still recommended because it
makes the code simpler.
If the initialization failed, which means the Crosswalk runtime doesn't exist or doesn't match
the app, you could use XWalkUpdater to prompt the user to download suiteble Crosswalk
runtime.
For example:
public class MyActivity extends Activity implements XWalkInitializer.XWalkInitListener {
XWalkView mXWalkView;
XWalkInitializer mXWalkInitializer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Must call initAsync() before anything that involes the embedding API, including
// invoking setContentView() with the layout which holds the XWalkView object.
mXWalkInitializer = new XWalkInitializer(this, this);
mXWalkInitializer.initAsync();
// Until onXWalkInitCompleted() is invoked, you should do nothing with the embedding API
// except the following:
// 1. Instanciate the XWalkView object
// 2. Call XWalkPreferences.setValue()
// 3. Call XWalkView.setUIClient()
// 4. Call XWalkView.setResourceClient()
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, true);
setContentView(R.layout.activity_xwalkview);
mXWalkView = (XWalkView) findViewById(R.id.xwalkview);
mXWalkView.setUIClient(new MyXWalkUIClient(mXWalkView));
mXWalkView.setResourceClient(new MyXWalkResourceClient(mXWalkView));
}
@Override
public void onXWalkInitCompleted() {
// Do anyting with the embedding API
mXWalkView.load("http://crosswalk-project.org/", null);
}
@Override
public void onXWalkInitStarted() {
}
@Override
public void onXWalkInitCancelled() {
// Perform error handling here
}
@Override
public void onXWalkInitFailed() {
// Perform error handling here, or launch the XWalkUpdater
}
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
XWalkInitializer.XWalkInitListener
Interface used to initialize the Crosswalk runtime.
|
| Constructor and Description |
|---|
XWalkInitializer(XWalkInitializer.XWalkInitListener listener,
android.app.Activity activity)
Create an initializer for single activity.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancelInit()
Attempt to cancel the initialization.
|
boolean |
initAsync()
Initialize the Crosswalk runtime in background asynchronously.
|
public XWalkInitializer(XWalkInitializer.XWalkInitListener listener, android.app.Activity activity)
This method must be invoked on the UI thread.
listener - The XWalkInitializer.XWalkInitListener to use.activity - The activity which initiate the initializationpublic boolean initAsync()
This method must be invoked on the UI thread.
public boolean cancelInit()