我只是尝试使用其他活动的onActivitiResult

时间:2014-08-11 08:07:03

标签: android

Google登录连接错误

Android代码..

 public class GooglePlusPlugin implements ConnectionCallbacks,
 OnConnectionFailedListener{
 Activity resultactivity;
 private Activity activity;// activity is Unity3D currentActivity
 public void init(String objName, String CallbackName) {

    callbackName = CallbackName;
    unityObjectName = objName;
    mApiClient = new GoogleApiClient.Builder(activity, this, this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addScope(Plus.SCOPE_PLUS_PROFILE).build();

    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            resultactivity = new ResultActivity();
            mConnectionProgressDialog = new ProgressDialog(activity);
            mConnectionProgressDialog.setMessage("Signing in...");
        }
    });
}
 @Override
 public void onConnectionFailed(final ConnectionResult result) {
    if (!mConnectionProgressDialog.isShowing()) {
        if (result.hasResolution()) {
            try {
                result.startResolutionForResult(resultactivity,
                result.getErrorCode());
                return;
            } catch (SendIntentException e) {
                mApiClient.connect();
            }
        }
    }
}
}

startResolutionForResult对onActivityResult的调用

我尝试使用onActivityResult其他活动,因为没有扩展GooglePlusPlugin中的活动

public class ResultActivity extends FragmentActivity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_RESOLVE_ERR
            && resultCode == RESULT_OK) {
        GooglePlusPlugin.getInstance().reconnect(requestCode, resultCode);
        finish();
    }
}

但失败了......

错误是

Caused by: java.lang.NullPointerException
at android.app.Activity.startIntentSenderForResultInner(Activity.java:3560)
at android.app.Activity.startIntentSenderForResult(Activity.java:3536)
at android.app.Activity.startIntentSenderForResult(Activity.java:3503)
at com.google.android.gms.common.ConnectionResult.startResolutionForResult(Unknown Source)
at kr.co.crooz.plugin.googleplus.GooglePlusPlugin.onConnectionFailed(GooglePlusPlugin.java:212)

为什么startIntentSenderForResult需要,我不知道如何使用它。 怎么解决?

感谢您阅读长代码

私人活动活动;活动已经从另一部分开始。

我喜欢很长的内容。那部分不是。

 try {
        this.unityPlayerClass = Class
                .forName("com.unity3d.player.UnityPlayer");
        this.unityPlayerActivityField = this.unityPlayerClass
                .getField("currentActivity");
        this.unitySendMessageMethod = this.unityPlayerClass.getMethod(
                "UnitySendMessage", new Class[] { String.class,
                        String.class, String.class });

        this.activity = getActivity();
    }

private Activity getActivity() {
    if (this.unityPlayerActivityField != null) {
        try {
            Activity activity = (Activity) this.unityPlayerActivityField
                    .get(this.unityPlayerClass);
            if (activity == null) {
                Log.d(TAG,
                        "Something has gone terribly wrong. The Unity Activity does not exist. This could be due to a low memory situation");
            }
            return activity;
        } catch (Exception e) {
            Log.d(TAG, "error getting currentActivity: " + e.getMessage());
        }
    }

    return this.activity;
}

1 个答案:

答案 0 :(得分:0)

您的活动为空

private Activity activity;// activity is Unity3D currentActivity

你在这里声明它,但你永远不会从unity3D获取活动,因为我猜你试图这样做,这将导致你的活动为null并将抛出nullpointerexeption