Questions about Two Way Sync Using SyncAdapter and SyncService in android

by himanshu jain » Sat, 29 Jan 2011 08:22:17 GMT


Sponsored Links
 Hi All,

I am trying to implement two way sync.

1) I tried using SampleSyncAdapter Code first it works on emulator but
not on Device , then i tried to write SyncAdapter with SyncService as
a demo app with AccountAuthenticator, as per Documentation for
SampleSyncAdapter SyncService gets called on
ACTION_AUTHENTICATOR_INTENT but my service does not gets started on
device , i defined service in manifest and all things but does not
work on device it gets started on Emulator.

2) If i port my app on device i can see only first name and last name
fields how can i see all the fields available for contact
application ?? can i edit them also utilizing the same native
editor??.

3) I planning to add contentobserver for sync from device to cloud
whenever there is change corresponding to my account in contact table
i want to sync it after listening through contentobserver.Is that
correct ??.

thanks

-- 



Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by Dmitri Plotnikov » Mon, 31 Jan 2011 03:42:44 GMT


 Hi Himanshu,

1) SampleSyncAdapter is still a good source of inspiration.  It has some
issues and plan to have them fixed in the nearest future.

2) In releases of Android from Eclair through Gingerbread integrated editing
of 3rd party contacts is poorly supported.  The trick is to insert a data
row, "Edit in MyApp", which would take the user to your app and your app
would then provide an editor activity.  Also, there is no provision in the
Contacts UI for creating new contacts in 3rd party accounts.  We have fixed
those issues in Honeycomb.  Now you can specify two activities in your
metadata xml file: one for creating new contacts and one for editing
existing ones and voil! - you have seamless integration.  Of course, it's a
bit too soon to rely on Honeycomb as the dominant version of Android ;-)  So
for now you will need to either go with the described hack or only allow
creation/editing of contacts through your app.

3) Please consider an alternative to using content observers for a sync
adapter.  There are several reasons:

- In order to receive notifications, your process will need to be running at
all times. Or it would have to have a broadcast receiver, which is very very
costly.
- Content observer notifications are not reliable.  If your process is not
running at the time the change occurs, the notification will never be
delivered.  A broadcast receiver will solve that problem, but please don't
use broadcast receivers for this!
- Contacts provider sends out non-discriminated notifications.  Whenever
anything (e.g. chat presence) changes, all observers are notified whether
they have supplied a specific URI or not.

What you do want to use is the DIRTY flag and the CALLER_IS_SYNCADAPTER
query parameter and let SyncManager invoke your sync adapter.  It does some
sophisticated scheduling and you want to take advantage of it.

Cheers,
- Dmitri






-- 


Sponsored Links


Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by himanshu jain » Tue, 01 Feb 2011 05:37:47 GMT


 Dmitri

Thanks a lot for spending time to answer my questions at least some
doubts are faded off.

1) I understand to use own activity for editing and creating new
contacts.

2) Ok, if i avoid ContentObserver even i had that in mind might
require something to be running in background which is bad agreed.

3) But, there are two use cases first if there is a button that say
sync now and i send request using requestSync() method will it start
immediate sync via SyncManager or again it will depend upon
SyncManager discretion?? if thats true i cannot start immediate
Sync ??.

Second use case how would i know if there is a change corresponding
to my account in raw_contact utilizing best practice push
notification ?? so that i can trigger syncing.

thanks Dimitri for your time and ideas


On Jan 30, 11:42am, Dmitri Plotnikov <dplotni...@google.com> wrote:

--



Re: Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by Dmitri Plotnikov » Tue, 01 Feb 2011 05:49:40 GMT


 ending requestSync to contentresolver is the right way to go if you want an
explicit button to request sync. This is what applications like Calendar and
Gmail do when you push the "Sync" button. ContentProvider will also request
sync whenever there is a change in the data.

You should query raw contacts that have the DIRTY flag set. These are the
added, deleted or changed contacts. Your sync adapter should reset this
flag after syncing up changes. It also needs to physically remove deleted
contacts from the database. In both cases it needs to supply the
CALLER_IS_SYNCADAPTER query parameter - otherwise the protocol won't work.

Cheers,
- Dmitri

On Mon, Jan 31, 2011 at 1:37 PM, himanshu jain <himanshu....@gmail.com>wrote:


--



Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by himanshu jain » Tue, 01 Feb 2011 06:44:25 GMT


 Dmitri

thanks once again

But why my SyncService not gets started by SyncManager on Device i
dont know , and i explicitly call requestSync flow is not going inside
onPerformSync.?


thanks

On Jan 31, 1:49pm, Dmitri Plotnikov <dplotni...@google.com> wrote:

--



Re: Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by Dmitri Plotnikov » Tue, 01 Feb 2011 08:11:45 GMT


 o you see your account in Settings/Accounts?   Does it have contact syncing
enabled?

On Mon, Jan 31, 2011 at 2:44 PM, himanshu jain <himanshu....@gmail.com>wrote:


--



Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by himanshu jain » Tue, 01 Feb 2011 08:26:37 GMT


 Dmitri

Yes i created my account when i go to Account & sync section through
settings and after adding my account , sync gets enabled in DDMS i can
see SyncManager gets called twice once on setIsSyncable and on
setSyncAutomatically but My Service associated with SyncAdapter does
not gets started and also i dont reach to onPerformSync immediately
when i explicitly call requestSync.

thanks

On Jan 31, 4:11pm, Dmitri Plotnikov <dplotni...@google.com> wrote:

--



Re: Re: Questions about Two Way Sync Using SyncAdapter and SyncService in android

by Dmitri Plotnikov » Tue, 01 Feb 2011 08:54:21 GMT


  would double-check every line of AndroidManifest.xml, compare it with the
one in SampleSyncAdapter to see if anything's missing.

On Mon, Jan 31, 2011 at 4:26 PM, himanshu jain <himanshu....@gmail.com>wrote:


--



Other Threads

1. crashing map

Hey there...

My application using google maps was working just fine.. I left it for
a while.. and suddenly out of the blue.. it crashes by just touching
on the map... the only change I've done was to change a .png file for
another image..
Anyway.. I get a NullPointerException.. on the de{*filter*}.. nd the
logcat writes this errors:

06-30 01:39:16.756: ERROR/ActivityThread(619): Failed to find provider
info for android.server.checkin
06-30 01:39:16.856: ERROR/ActivityThread(619): Failed to find provider
info for android.server.checkin
06-30 01:39:23.546: ERROR/ActivityThread(738): Failed to find provider
info for com.google.settings
06-30 01:39:23.566: ERROR/ActivityThread(738): Failed to find provider
info for com.google.settings
06-30 01:39:23.606: ERROR/ActivityThread(738): Failed to find provider
info for com.google.settings

and more

06-30 01:39:23.606: ERROR/ActivityThread(738): Failed to find provider
info for com.google.settings
06-30 01:39:27.527: ERROR/MapActivity(738): Couldn't get connection
factory client
06-30 01:39:56.476: ERROR/AndroidRuntime(738): Uncaught handler:
thread main exiting due to uncaught exception
06-30 01:39:56.627: ERROR/AndroidRuntime(738):
java.lang.NullPointerException
06-30 01:39:56.627: ERROR/AndroidRuntime(738):     at
com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:
617)
06-30 01:39:56.627: ERROR/AndroidRuntime(738):     at
com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:
586)
06-30 01:39:56.627: ERROR/AndroidRuntime(738):     at
com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:
498)
06-30 01:39:56.627: ERROR/AndroidRuntime(738):     at
com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:
572)
06-30 01:39:56.627: ERROR/AndroidRuntime(738):     at
com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:
63)

there's much more.. but i guess its something to do with the maps
itself.. any help please?

-- 

2. OOT: Saya Tidak Menjual BB 9100

Rekan milis, 

Mohon bantuannya meneruskan email ini ke milis lain maupun forum yang
rekan-rekan ikuti. Sekadar untuk jaga-jaga, tanpa bermaksud menuduh,
memojokkan, atau mendiskreditkan seseorang. 

Barusan teman seorang rekan di milis ini menelepon saya. Ia ingin
konfirmasi apakah saya benar menjual BlackBerry 9100. Ceritanya, ia
mendapatkan penawaran dari seseorang yang mengaku bernama lengkap Herry
Setiadi Wibowo. Nah, rekan milis itu curiga karena nomor ponsel yang
diberikan penjual kok bukan berakhiran "angka kebangsaan" saya. Temannya
langsung diminta menelepon dan berbicara langsung dengan saya. 

Beberapa kebetulan yang menarik dicermati:
* Si penjual bernama lengkap Herry Setiadi Wibowo. Ejaannya sama persis
dengan saya. 
* Ia menggunakan nomor IM3. 
* Ia mengaku tinggal di Surabaya. 
* Alamat emailnya herry.setiadi.wibowo (at) gmail.com   
* Si calon pembeli sudah coba iseng ke ATM dan memasukkan nomor rekening
yang diberikan oleh penjual. Eh, nama pemilik rekening benar Herry
Setiadi Wibowo.

Sore atau malam ini, teman seorang rekan milis tersebut akan
mem-forward-kan email dari Herry Setiadi Wibowo yang bukan saya itu.
Nanti coba kita lihat nomor HP dan nomor rekening BCA-nya. 

Tanpa bermaksud negative thinking, mohon lakukan tinjau silang sebelum
bertransaksi. Kalau memungkinkan, coba deh diajak ketemuan langsung.
Andaikan ia benar bernama lengkap Herry Setiadi Wibowo dan tinggal di
Surabaya, ntar saya bantu mengundang wartawan deh. Kayaknya menarik
untuk diprofilkan. Ada dua orang yang tiga kata nama lengkapnya sama
persis, trus kebetulan juga tinggal di kota yang sama. 

Saya, Herry SW yang bernama lengkap Herry Setiadi Wibowo, dapat
dihubungi via email japri milis (at) hsw9900.com. 

Terima kasih. 



Salam,


Herry SW

-- 
"Indonesian Android Community [id-android]" 

3. Update: WTS : White Spica rooted

4. Access and Update Android Contacts in native libraries(C/C++)

5. Bump is letting users send paid apps?

6. Notification Icon - One for Status and one for Pull Down List?

7. Access and Update Android Contacts in native libraries(C/C++)