Authenticator addAccount 导致崩溃
Authenticator addAccount causing crash
我正在尝试编写一个 Authenticator 组件,但我不断收到无法解决的运行时异常。我所实现的只是 addAccount() 方法。我尝试通过 Android 的设置 -> 帐户 -> 添加帐户来添加帐户。我 select 成功出现在列表中的帐户类型。 Authenticator 启动并调用 addAccount()。它在成功启动身份验证 Activity 之前停止并抛出此异常:
01-28 17:38:57.599 886-1466/? W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at com.android.server.accounts.AccountManagerService$Session.onResult(AccountManagerService.java:2203)
at android.accounts.IAccountAuthenticatorResponse$Stub.onTransact(IAccountAuthenticatorResponse.java:59)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
Authenticator的addAccount()实现:
final Bundle bundle = new
final Intent intent = new Intent(context, AuthenticatorActivity.class);
intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
我刚刚解决了同样的问题,但我的解决方案不一定适用于你。
我正在使用 AndroidAnnotations,我的 AuthenticatorActivity
class 被注释为 @EActivity
。因此,我应该使用 AuthenticatorActivity_.class
(注意下划线!)构造意图,这是 AndroidAnnotations 为我生成的 class。我原来的 class 会有很多空变量。
以后,我必须小心记住这一点,因为在构建时没有错误或警告。
希望对你也有帮助。
顺便说一句,我找到了一个相关的 AndroidAnnotations Issue,它讨论了我们必须明确使用生成的 class 名称的其他场景。还有一个关于如何解决这个问题的讨论,但问题仍然悬而未决。
我正在尝试编写一个 Authenticator 组件,但我不断收到无法解决的运行时异常。我所实现的只是 addAccount() 方法。我尝试通过 Android 的设置 -> 帐户 -> 添加帐户来添加帐户。我 select 成功出现在列表中的帐户类型。 Authenticator 启动并调用 addAccount()。它在成功启动身份验证 Activity 之前停止并抛出此异常:
01-28 17:38:57.599 886-1466/? W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.NullPointerException
at com.android.server.accounts.AccountManagerService$Session.onResult(AccountManagerService.java:2203)
at android.accounts.IAccountAuthenticatorResponse$Stub.onTransact(IAccountAuthenticatorResponse.java:59)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
Authenticator的addAccount()实现:
final Bundle bundle = new
final Intent intent = new Intent(context, AuthenticatorActivity.class);
intent.putExtra(AuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
intent.putExtra(AuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
intent.putExtra(AuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
return bundle;
我刚刚解决了同样的问题,但我的解决方案不一定适用于你。
我正在使用 AndroidAnnotations,我的 AuthenticatorActivity
class 被注释为 @EActivity
。因此,我应该使用 AuthenticatorActivity_.class
(注意下划线!)构造意图,这是 AndroidAnnotations 为我生成的 class。我原来的 class 会有很多空变量。
以后,我必须小心记住这一点,因为在构建时没有错误或警告。
希望对你也有帮助。
顺便说一句,我找到了一个相关的 AndroidAnnotations Issue,它讨论了我们必须明确使用生成的 class 名称的其他场景。还有一个关于如何解决这个问题的讨论,但问题仍然悬而未决。