我尝试实施https://facebook.github.io/react-native/docs/integration-with-existing-apps.html
但是当我尝试实现活动生命周期回调onPause,onResume和onDestroy时,我的Android Studio抱怨:无法解析onPause方法。
https://github.com/facebook/react-native/issues/10326
还有其他人有这个问题吗?
答案 0 :(得分:1)
答案 1 :(得分:0)
我按照以下方式使用它:
@Override
public void onHostResume() {
Log.i(TAG, "- onResume");
// Within {@code onPause()}, we pause location updates, but leave the
// connection to GoogleApiClient intact. Here, we resume receiving
// location updates if the user has requested them.
if (mGoogleApiClient.isConnected() && mRequestingLocationUpdates) {
checkLocationSettings();
Log.i(TAG,"on resume");
}
}
@Override
public void onHostPause() {
Log.i(TAG, "- onPauase");
// Stop location updates to save battery, but don't disconnect the GoogleApiClient object.
if (mGoogleApiClient.isConnected()) {
stopLocationUpdates();
Log.i(TAG,"on pause");
}
}
@Override
public void onHostDestroy() {
Log.i(TAG, "- onDestroy");
}
导入LifecycleEventListener接口
导入com.facebook.react.bridge.LifecycleEventListener;
在java类构造函数中注册侦听器
<强> getReactApplicationContext()addLifecycleEventListener(本); 强>
覆盖上述必要的方法