public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.viewlist);
dbHelper = new RecordsDbAdapter(this);
dbHelper.open();
//Add some data
// dbHelper.insertSomeRecords();
//Generate ListView from SQLite Database
displayListView();
// setContentView(R.layout.expense_entry);
Button deleteBtn = (Button) this.findViewById(R.id.btn_delete);
deleteBtn.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
//do something
ViewGroup parent = (ViewGroup) v.getParent();
// final ConstraintLayout c = this;
for (int itemPos = 0; itemPos < parent.getChildCount(); itemPos++) {
View view = parent.getChildAt(2);
if (view.getParent() == parent) {
dbHelper.deleteSingleRow(String.valueOf(view.findViewById(R.id.textViewDateTime)));
dataAdapter.notifyDataSetChanged();
}
}}
JVM启用了详细的GC日志切换功能,并且在上面的代码运行时没有GC日志。那么我们可以得出结论,如果实际延迟和经过的CPU时间之间存在巨大差异,那么该线程是否被操作系统抢占了?
我观察到了巨大的差异:延迟超过1秒,timeElpasedCPU只有几毫秒。