如何使用ContentObserver..?
我对这个东西很陌生,找不到合适的答案。我自己做了一些事情,我不知道我仪式到什么程度。它不起作用。
package com.aqui.observer;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
public class ObserverActivity extends Activity {
private MyObserver observer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
observer = new MyObserver(new Handler());
getContentResolver().registerContentObserver(ContactsContract.Data.CONTENT_URI, true, observer);
}
@Override
protected void onStop() {
super.onStop();
getContentResolver().unregisterContentObserver(observer);
}
@Override
protected void onStart() {
super.onStart();
getContentResolver().registerContentObserver(ContactsContract.Data.CONTENT_URI, true, observer);
}
}
这是我的观察者。
package com.aqui.observer;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Log;
public class MyObserver extends ContentObserver{
public MyObserver(Handler handler) {
super(null);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.e("CHANGEsTrappedSuccessfully", "YEAH..YEAh");
}
}
先感谢您。
I'm very new to this stuff and could't find an appropriate answer. I did something by myself, i don't know to what extent i'm rite. and its not working.
package com.aqui.observer;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract;
public class ObserverActivity extends Activity {
private MyObserver observer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
observer = new MyObserver(new Handler());
getContentResolver().registerContentObserver(ContactsContract.Data.CONTENT_URI, true, observer);
}
@Override
protected void onStop() {
super.onStop();
getContentResolver().unregisterContentObserver(observer);
}
@Override
protected void onStart() {
super.onStart();
getContentResolver().registerContentObserver(ContactsContract.Data.CONTENT_URI, true, observer);
}
}
and this is my observer.
package com.aqui.observer;
import android.database.ContentObserver;
import android.os.Handler;
import android.util.Log;
public class MyObserver extends ContentObserver{
public MyObserver(Handler handler) {
super(null);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
Log.e("CHANGEsTrappedSuccessfully", "YEAH..YEAh");
}
}
thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论