Skip to main content

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​

parameterData TypeRequiredAttribute Description
activityandroid.app.ActivityYesActivity that displays the host view
optionsandroid.os.BundleNoInitialize parameters,USER_ID,HTTP_CACHE_LIMIT_STORAGE,HTTP_CACHE_PATH, etc.
options.HTTP_CACHE_PATHStringNoHTTP cache path
options.HOST_PAUSE_DELAY_MILLISlongNoDelay pausing the js engine after the host returns to the background, unit: milliseconds
reassignbooleanNotrue: 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
listenerOnTJCreateHandleListenerNoonSuccess/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​

parameterData TypeRequiredAttribute Description
tagjava.lang.ObjectYesObject 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​

parameterData TypeRequiredAttribute Description
tagjava.lang.ObjectNoObject 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);
}
}