标签:prot hang server end 数据库 set and instance extends
package com.itheima.contentobserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//注册内容观察者,观察者就生效了,可以接受内容提供者发出的通知
ContentResolver resolver = getContentResolver();
//arg0:指定接收哪个内容提供者发出的通知
resolver.registerContentObserver(Uri.parse("content://sms"),
true, //如果为true,以这个uri作为开头的uri上的数据改变了,该内容观察者都会收到通知
new MyObserver(new Handler()));
}
class MyObserver extends ContentObserver{
public MyObserver(Handler handler) {
super(handler);
// TODO Auto-generated constructor stub
}
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
System.out.println("短信数据库改变");
}
}
}
标签:prot hang server end 数据库 set and instance extends
原文地址:http://www.cnblogs.com/SoulCode/p/6393331.html