我对这些东西很新,但找不到合适的答案。我自己做了一些事情,我不知道我的仪式到底有多大。它不起作用。
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");
}
}
提前谢谢。