egret-docs-master/Native/manual/runtimestate.md

77 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: 事件回调
---
# 运行过程中 runtime 的事件回调
## state
- 消息类型
```
{"state”:”starting”} index加载成功
{"state”:”running”} js加载成功开始运行游戏
```
- 注册监听以Android为例
```java
private void setExternalInterfaces() {
// handle the state change Event during the running
nativeAndroid.setExternalInterface("@onState", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
String str = "Native get onState message: ";
str += message;
Log.e(TAG, str);
}
});
}
```
## error
- 消息类型
```
{"error":"load"} index加载失败
{"error":"start"} js加载失败
{"error”:”stopRunning”} 运行过程中出现异常中断了引擎的心跳一般会先抛出jsError
```
- 注册监听以Android为例
```java
private void setExternalInterfaces() {
// handle the error Event during the running
nativeAndroid.setExternalInterface("@onError", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
String str = "Native get onError message: ";
str += message;
Log.e(TAG, str);
}
});
```
## jsError
- 注册监听以Android为例
```java
private void setExternalInterfaces() {
// handle the error Event during the running
nativeAndroid.setExternalInterface("@onJSError", new INativePlayer.INativeInterface() {
@Override
public void callback(String message) {
// 参数为堆栈信息
String str = "Native get onJSError message: ";
str += message;
Log.e(TAG, str);
}
});
```