【问题标题】:FragmentActivity﹕ Activity result delivered for unknown FragmentFragmentActivity:为未知片段传递的活动结果
【发布时间】:2016-04-13 02:22:31
【问题描述】:

下面的 google api 调用没有产生任何回调。只有一个警告“FragmentActivity:为未知片段传递的活动结果。”

        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();

【问题讨论】:

  • 您是否在 findFitnessDataSources() 中注册了您的移动客户端?
  • 那是另一种情况,“已连接!!”标签没有出现意味着 findFitnessDataSources() 也不会执行
  • .enableAutoManage 需要扩展,ng FragmentActivity 你在这个活动/片段中扩展了什么?
  • 另外,您可以通过 .addConnectionCallbacks(new GoogleApiClient.OnConnectionFailedListener(){.....}).build(); 自行管理连接失败;
  • 面临同样的问题。

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


【解决方案1】:

我不确定这是否是 OP 的问题,但如果其他人遇到上述警告,请检查您 片段中进行的任何 startActivityForResult 调用。在我的例子中,我将这些调用从活动中移到了一个片段中,并保持原样。但是,当从片段内部制作时,您需要先调用 getActivity(),如下所示:

getActivity().startActivityForResult(intent, RESPONSE_CODE);

如果不这样做会导致“为未知片段传递的活动结果”错误,并且没有响应被传递给要处理的活动。

【讨论】:

    【解决方案2】:

    如果您使用高于 23.1.0 的版本,请尝试将您的支持库降级到 23.1.0。

    【讨论】:

      【解决方案3】:

      在苦苦挣扎后得到了这个问题的解决方案。新 API 已发布,此问题已在其中解决。所以只需更新你的 build.gradle 文件:

      编译'com.google.android.gms:play-services-fitness:10.0.0'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多