I have a ListActivity
with a SMS ContentObserver
. The ListView
displays
SMS sent/received.
Whenever there is change in the SMS database (sent/received), the observer
calls a function within the Activity
which updates the ListView
.
This works ok in FROYO. But in ICS I get the following
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Please let me know what could be the issue.
The following is the top level code.
public class MyList extends ListActivity implements OnInitListener{
@Override
protected void onDestroy() {
super.onDestroy();
MyList.this.getContentResolver()
.unregisterContentObserver(smsObserver);
}
@Override
protected void onPause() {
super.onPause();
MyList.this.getContentResolver()
.unregisterContentObserver(smsObserver);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.MyList );
registerSmsEventObserver();
updateList();
}
@Override
protected void onResume() {
super.onResume();
registerSmsEventObserver();
}
updateList() {
//fill up the listview
}
private void registerSmsEventObserver() {
if (smsObserver != null)
return;
smsObserver = new ContentObserver(null) {
public void onChange(boolean selfChange) {
updateList();
}
};
MyList.this.getContentResolver().registerContentObserver(
Uri.parse("content://sms"), true, smsObserver);
}
}