今天使用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):
@Override protected void onPause() { super.onPause(); if (mReactInstanceManager != null) { mReactInstanceManager.onHostPause(this); } } @Override protected void onResume() { super.onResume(); if (mReactInstanceManager != null) { mReactInstanceManager.onHostResume(this, this); } } @Override protected void onDestroy() { super.onDestroy(); if (mReactInstanceManager != null) { mReactInstanceManager.onHostDestroy(); } } @Override public void onBackPressed() { if (mReactInstanceManager != null) { mReactInstanceManager.onBackPressed(); } else { super.onBackPressed(); } }