如何实现在Android上的帐户没有SyncAdapter [英] How do I implement an Account on Android without a SyncAdapter

查看:205
本文介绍了如何实现在Android上的帐户没有SyncAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行一个登录系统,利用内置帐户系统(带的AccountManager API)的Andr​​oid应用程序。

I am implementing a login system for an Android application utilizing the built-in accounts system (with the AccountManager APIs).

一切都很好在Android 2.2+,但是在Android 2.1不包括SyncAdapter导致重新启动的帐户设置屏幕(请参阅<一href="http://$c$c.google.com/p/android/issues/detail?id=5009">http://$c$c.google.com/p/android/issues/detail?id=5009和<一href="http://stackoverflow.com/questions/3085242/accountmanager-without-a-syncadapter">AccountManager没有SyncAdapter?)

All is well and good on Android 2.2+, but on Android 2.1 not including a SyncAdapter causes reboots in the account settings screen (see http://code.google.com/p/android/issues/detail?id=5009 and AccountManager without a SyncAdapter?)

要解决这个问题,我实现存根SyncAdapter,刚刚返回的IBinder onBind(意向意图) ,并添加相关的东西的清单。这在Android 2.1解决了重启问题。

To get around this I implemented a stub SyncAdapter, which just returns null from IBinder onBind(Intent intent), and added the relevant stuff to the manifest. This resolves the reboot issue on Android 2.1.

但它引入了另一个问题:在一个帐户中添加了Android系统,一段时间后,启动一个帐户同步。虽然没有发生错误(事实上我SyncAdapter什么也不做,就没有办法,除非通过返回会导致错误),同步图标保持停留在顶部通知栏。这将导致Android同步系统维护的永久唤醒锁,$ P $睡觉pventing设备。

However it introduces a further problem: after an account is added the Android system will, sometime later, initiate an account sync. Although no errors occur (indeed my SyncAdapter does nothing, it has no way to cause errors unless by returning null), the sync icon stays stuck in the notification bar at the top. This results in the Android sync system maintaining a permanent wake-lock, preventing the device from sleeping.

帐户未列出在帐户设置屏幕的任何可同步组件(数据与同步标题下),并始终显示同步熄灭在(的帐户列表同步状态即使在同步图标在通知栏中可见)。禁用帐户同步不删除的问题。除去帐户停止的问题。

The account does not list any syncable components in the account settings screen (under the 'Data and synchronization' header), and always displays 'Sync is off' for the sync status in the list of accounts (even while the sync icon is visible in the notifications bar). Disabling account syncing does not remove the problem. Removing the account stops the problem.

我的猜测是我不应该返回null。我应该返回ThreadedSyncAdapter的基本实现?任何帮助得到一个账户系统没有关联同步的2.1和2.2 +正常工作是非常AP preciated。

My guess is I should not be returning null. Should I be returning a basic implementation of ThreadedSyncAdapter? Any help getting an account system without an associated sync working properly on 2.1 and 2.2+ is much appreciated.

推荐答案

我之类的解决我自己的问题:你不能返回 onBind 为您服务的方式 - 你必须返回的IBinder AbstractThreadedSyncAdapter

I sort of solved my own problem: you cannot return null from the onBind method of your service - you must return the IBinder of an AbstractThreadedSyncAdapter.

这有添加进入帐户设置页面的数据和同步部分,即使我实施 AbstractThreadedSyncAdapter 的什么都不做的不良影响;我希望避免这种情况。

This has the undesired effect of adding an entry into the Data and Synchronization section of the account settings page, even though my implementation of AbstractThreadedSyncAdapter does nothing; I was hoping to avoid this.

总之,为了利用账户系统在Android中,你必须:

To summarize, in order to make use of the accounts system in Android you must:

  • 实施有一个的IntentFilter android.content.SyncAdapter
  • 系统服务
  • 在此服务必须返回的IBinder AbstractThreadedSyncAdapter 实施从它的 onBind 方法。
  • 这就必要条件是你有一个的ContentProvider (可以只是一个存根实现),它被称为 contentAuthority 在SyncAdapter XML文件中。
  • 这有不利的方面,你的ContentProvider列出的数据和同步标题下在您的帐户设置页面。
  • Implement a service that has an IntentFilter for android.content.SyncAdapter.
  • This service must return the IBinder of an AbstractThreadedSyncAdapter implementation from it's onBind method.
  • This then necessitates that you have a ContentProvider (can just be a stub implementation) that is referred to as the contentAuthority in your SyncAdapter XML file.
  • This has the down-side that your ContentProvider is listed under the Data and Synchronization header on your account settings page.

这篇关于如何实现在Android上的帐户没有SyncAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆