0
我正在使用ContentProvider
来访问数据库并在我的Service
类中构建通过HTTP发送数据的JSON请求。是否需要将内容提供者代码放入线程
须藤代码如下
Cursor cursor = this.getContentResolver().query(
DB.EMPLOYEE_URI,
DB.EMPLOYEE.PROJECTION,
null, null, null);
while (cursor.moveToNext()) {
Employee empInfo= new Employee();
int id = cursor.getInt(cursor
.getColumnIndex(DB.EMPLOYEE.COL._ID));
String name= cursor.getString(cursor
.getColumnIndex(DB.EMPLOYEE.COL.EMPLOYEE_NAME));
String reqJSON = getGSON()
.toJson(empInfo);
}
那么,我需要把它包起来了上面的代码线程或异步任务的内部,使得它不会中断主线程,因为我不知道getContentResolver是非块操作。