无法解析React Native示例应用程序的onPause方法

时间:2016-10-10 14:58:57

标签: react-native react-native-android

我尝试实施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

还有其他人有这个问题吗?

2 个答案:

答案 0 :(得分:1)

似乎使用onHostPause而不是onPause应该是解决方案,同样解决其他回调抱怨。

检查此enter image description here以获取详细信息:

答案 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");
}
  1. 导入LifecycleEventListener接口

    导入com.facebook.react.bridge.LifecycleEventListener;

  2. 在java类构造函数中注册侦听器

    <强> getReactApplicationContext()addLifecycleEventListener(本);

  3. 覆盖上述必要的方法