android - FragmentActivity:为未知 Fragment 传递的 Activity 结果

标签 android android-fragments google-play-services google-api-client

下面的 google api 调用没有产生任何回调。只有“FragmentActivity:Activity result delivered for unknown Fragment”的警告。

        mClient = new GoogleApiClient.Builder(this)
                    .addApi(Fitness.SENSORS_API)
                    .addScope(new Scope(Scopes.FITNESS_ACTIVITY_READ_WRITE))
                    .addConnectionCallbacks(
                            new GoogleApiClient.ConnectionCallbacks() {
                                @Override
                                public void onConnected(Bundle bundle) {
                                    Log.i(TAG, "Connected!!!");
                                    // Now you can make calls to the Fitness APIs.
                                    findFitnessDataSources();
                                }

                                @Override
                                public void onConnectionSuspended(int i) {
                                    // If your connection to the sensor gets lost at some point,
                                    // you'll be able to determine the reason and react to it here.
                                    if (i == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST) {
                                        Log.i(TAG, "Connection lost.  Cause: Network Lost.");
                                    } else if (i
                                            == GoogleApiClient.ConnectionCallbacks.CAUSE_SERVICE_DISCONNECTED) {
                                        Log.i(TAG,
                                                "Connection lost.  Reason: Service Disconnected");
                                    }
                                }
                            }
                    )
                    .enableAutoManage(this, 0, new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(ConnectionResult result) {
                            Log.i(TAG, "Google Play services connection failed. Cause: " +
                                    result.toString());
                            }
                 })
                .build();
        mClient.connect();

最佳答案

我不确定这是否是 OP 的问题,但如果其他人遇到上述警告,请检查您在 fragment 进行的任何 startActivityForResult 调用。就我而言,我将这些调用从 Activity 中移到了 fragment 中,并保持原样。但是,当从 fragment 内部创建时,您需要先调用 getActivity(),如下所示:

getActivity().startActivityForResult(intent, RESPONSE_CODE);

未能执行此操作会导致“为未知 fragment 传递的 Activity 结果”错误,并且不会将任何响应传递给要处理的 Activity 。

关于android - FragmentActivity:为未知 Fragment 传递的 Activity 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36587428/

相关文章:

android - 我的 Android 过渡动画只工作一次

android - Android:gradle中应包含哪个Google Play服务版本

android - 检索到访问 token :null. com.google.android.gms.auth.GoogleAuthException:未知

android - Android Studio 检测到 GoogleApiClient 的内存泄漏

java - 安卓,改造 2 : How to make calls every 5 second?

Android通知打开DialogFragment

android - 如何检查应用程序是否可移动到 sd

android - fragment - 您是否必须在包含整个 Activity 的 fragment 周围使用 Activity Wrapper?

android - 无法在多个选项卡中使用回收器 View

java - 从主要 Activity 更改 fragment 中的 setText 值