Host Management
1 Initialize Host
Before initializing the host, the host status is UNAVAILABLE.
TJHostHandle tjHostHandle calls createGameHandle to initialize the host, and the host state changes to WAITING.
1.1 Interface Prototype
void createGameHandle(Activity activity, Bundle options, OnTJHostCreateHandleListener listener)
1.2 Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| activity | android.app.Activity | Yes | Activity that displays the host view |
| options | android.os.Bundle | No | Initialize parameters,USER_ID,HTTP_CACHE_LIMIT_STORAGE,HTTP_CACHE_PATH, etc. |
| options.HTTP_CACHE_PATH | String | No | HTTP cache path |
| options.HOST_PAUSE_DELAY_MILLIS | long | No | Delay pausing the js engine after the host returns to the background, unit: milliseconds |
| reassign | boolean | No | true: Wait for destroyGameHandle to finish executing before creating a new gameHandle |
false: Do not destroy, only reset gameHandle | |||
Default value false, applicable to quickly restart the host activity | |||
| listener | OnTJCreateHandleListener | No | onSuccess/onFailure callback, onSuccess returns TJGameHandle instance |
2 Reset Host
Reset the `TJGameHandle` instance, and the host state changes to WAITING.
Used in conjunction with hostHandle.setTag(final Object tag) to mark the gameHandle within the current hostHandle, preventing state exceptions caused by quickly restarting the activity where the host is located.
2.1 Interface Prototype
void resetGameHandle(Object tag)
2.2 Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| tag | java.lang.Object | Yes | Object used to mark gameHandle |
3 Destroy Host
Destroy the `TJGameHandle` instance in `hostHandle`, and the host state changes to UNAVAILABLE.
3.1 Interface Prototype
void destroyGameHandle()
void destroyGameHandle(Object tag)
3.2 Parameter Description
| parameter | Data Type | Required | Attribute Description |
|---|---|---|---|
| tag | java.lang.Object | No | Object used to mark gameHandle |
4 Code Example
public class WebglHostSampleActivity extends AppCompatActivity {
private TJHostHandle hostHandle;
private Object mTag;
private WebglHostSampleActivity self;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
self = this;
mTag = System.identityHashCode(this);
Bundle hostBundle = new Bundle();
// TJHostHandle initialization
TJHostHandle.initialize(this, "sdkKey", "sdkSecret", new OnTJHostHandleInitializeListener() {
@Override
public void onSuccess(TJHostHandle res) {
hostHandle = res;
// create GameHandle
hostHandle.createGameHandle(self, hostBundle, new OnTJHostCreateHandleListener() {
@Override
public void onSuccess(TJHostHandle result) {
hostHandle.setTag(mTag);
}
@Override
public void onFailure(Throwable throwable) {
}
});
}
@Override
public void onFailure(Throwable throwable) {
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
hostHandle.resetGameHandle(mTag);
}
}