我对这些东西很陌生,找不到合适的答案。我自己做了一些事情,我不知道我到什么程度。它不工作。
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");
}
}
先感谢您。