i am making an sms app ,the problem is that when new sms received activity don't refresh listview ,i tried notiy datasetchanged but nothing happend. I placed code onresume method but i hangs my app when new sms receive.when i put code into asynctask it gives error.
void update() {
getAll.clear();
Uri SMS_INBOX = Uri.parse("content://mms-sms/conversations?simple=true");
Cursor c = getContentResolver().query(SMS_INBOX, null, null, null, "date DESC");
startManagingCursor(c);
count = new String[c.getCount()];
snippet = new String[c.getCount()];
thread_id = new String[c.getCount()];
String[] num=new String[c.getCount()];
date=new String[c.getCount()];
address=new String[c.getCount()];
c.moveToFirst();
for (int i = 0; i < c.getCount()-1; i++) {
count[i] = c.getString(c.getColumnIndexOrThrow("message_count"))
.toString();
thread_id[i] = c.getString(c.getColumnIndexOrThrow("_id"))
.toString();
snippet[i] = c.getString(c.getColumnIndexOrThrow("snippet"));
date[i]=c.getString(c.getColumnIndexOrThrow("date"));
Cursor cur = getContentResolver().query(Uri.parse("content://sms/"), null, "thread_id = " + thread_id[i], null, null);
cur.moveToFirst();
startManagingCursor(cur);
num[i] = getContactName(this,cur.getString(cur.getColumnIndexOrThrow("address")).toString());
address[i] = cur.getString(cur.getColumnIndexOrThrow("address")).toString();
getAll.add(count[i]+","+num[i]+","+snippet[i]);
Log.d("help",num[i]);
c.moveToNext();
}
adapter = new HomeAdapter(this, R.layout.sms, getAll,date);
adapter.notifyDataSetChanged();
list.setAdapter(adapter);
}
2.In OnResume
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
update();
}