views:

240

answers:

2

Hi, I am using ContentObserver on contacts. But here my problem is atleast once i have to launch my application other wise i am unable to get notification chages. My code like this

ContactsContentObserver cco = new ContactsContentObserver(handler);

    ContentResolver contentResolver = getContentResolver();

    contentResolver.registerContentObserver(RawContacts.CONTENT_URI,
    true, cco);

            }

private class ContactsContentObserver extends ContentObserver 
{
 public ContactsContentObserver(Handler h) 
 {
      super(h);
    }

    public void onChange(boolean selfChange) 
    {
       System.out.println("##########SOMEBODAY CHANGED ANYTHING AT THE CONTACTS");
       Toast.makeText(getApplication(),"####Updated####",Toast.LENGTH_LONG).show();


       }

.... Adv thanks. u can contact on [email protected]

A: 

IF you are developing an UI application with Android then whatever your code or functionality will only works once you launch your application. The better option for you to develop the service or Beckgroud process, which will be running in background on the device. And you dont even need to launch it. You are having an live example of OnScreen Keyboard of Android. That is one kind of application which wait for some sort of event or something and based on that it pop's up. Try to develop service and see what happens....

Rahul Patel
Ya i also have same idea. But is there any way to do it on Android manifest file. One more doubt is any way to check which contact is updated in android. But i dont want to use as a service.
Laxman
A: 

I assume you are wanting the ContentObserver to automatically run when something changes in the contacts. The problem is, something will need to call the code that registers that listener. What you probably could do is create a service that starts when the device finishes booting, registers the ContentObserver and then exits. The service does not need to continuously run as the ContentProvider framework will automatically call your code. Look into registering to receive the BOOT_COMPLETED_ACTION intent as per this post.

Chris Thompson
Ya i also have same idea. But is there any way to do it on Android manifest file. One more doubt is any way to check which contact is updated in android.
Laxman
The intent filtering stuff will be done in the manifest file when you register the service. Check out the android docs on intent filters
Chris Thompson