我已经使用Android开发者网站上的指南实现了我的同步适配器,但是当我运行代码时,我收到了一条Error Unparceling Bundlle消息。堆栈跟踪如下:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: error unparceling Bundle at
android.content.ContentResolver.validateSyncExtrasBundle(ContentResolver.java:1159) at
android.content.ContentResolver.requestSync(ContentResolver.java:1120)
我的目标是Marshmallow,最小的SDK是15.想法?
答案 0 :(得分:1)
在build()
对象上致电SyncRequest
之前,请将.setExtras(new Bundle())
设为如下所示:
SyncRequest request = new SyncRequest.Builder()
.syncPeriodic(syncInterval, flexTime)
.setSyncAdapter(account, authority)
.setExtras(new Bundle())
.build();
为我修复了错误。希望它适合你。
答案 1 :(得分:0)
这可能与您放入Bundle
的数据类型有关。请注意ContentResolver#requestSync
方法的javadoc - 并非所有类型都支持:
/**
* Start an asynchronous sync operation. If you want to monitor the progress
* of the sync you may register a SyncObserver. Only values of the following
* types may be used in the extras bundle:
* <ul>
* <li>Integer</li>
* <li>Long</li>
* <li>Boolean</li>
* <li>Float</li>
* <li>Double</li>
* <li>String</li>
* <li>Account</li>
* <li>null</li>
* </ul>
*
* @param account which account should be synced
* @param authority which authority should be synced
* @param extras any extras to pass to the SyncAdapter.
*/
public static void requestSync(Account account, String authority, Bundle extras) {
requestSyncAsUser(account, authority, UserHandle.myUserId(), extras);
}