React Native: alert : tried to show an alert while not attached to an activity

来源:互联网 发布:unity3d guitexture 编辑:程序博客网 时间:2024/06/01 08:08

今天使用alert来弹出消息时候,发现下方一直弹出一个黄色的错误提示:tried to show an alert while not attached to an activity,使用的是Android 4.x的机子。

经谷歌,发现是因为android->app->src->main->java下的MainActivity少了几个方法,将其补上就可以正常弹出Alert。另外尽量使用Alert.alert()来弹出alert(要先import Alert):

@Overrideprotected void onPause() {    super.onPause();    if (mReactInstanceManager != null) {        mReactInstanceManager.onHostPause(this);    }}@Overrideprotected void onResume() {    super.onResume();    if (mReactInstanceManager != null) {        mReactInstanceManager.onHostResume(this, this);    }}@Overrideprotected void onDestroy() {    super.onDestroy();    if (mReactInstanceManager != null) {        mReactInstanceManager.onHostDestroy();    }}@Override public void onBackPressed() {    if (mReactInstanceManager != null) {        mReactInstanceManager.onBackPressed();    } else {        super.onBackPressed();    }}


原创粉丝点击