开发者

Reg : Contact changes in Android

开发者 https://www.devze.com 2022-12-29 09:11 出处:网络
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

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 CONTA开发者_如何学GoCTS");
       Toast.makeText(getApplication(),"####Updated####",Toast.LENGTH_LONG).show();


       }

.... Adv thanks.


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....


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消