@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); staticHandlerPrint = new StaticHandlerPrint(this); startService(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { startService(new Intent(getBaseContext(), PrintNoteIntentService.class)); // Snackbar.make(view, "Replace with your own action", // Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); } }); DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db", null); db = helper.getWritableDatabase(); daoMaster = new DaoMaster(db); daoSession = daoMaster.newSession(); noteDao = daoSession.getNoteDao(); String textColumn = NoteDao.Properties.Test.columnName; String orderBy = textColumn + " COLLATE LOCALIZED ASC"; cursor = db.query(noteDao.getTablename(), noteDao.getAllColumns(), null, null, null, null, orderBy); String[] from = {textColumn, NoteDao.Properties.Comment.columnName}; int[] to = {android.R.id.text1, android.R.id.text2}; adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, to); listView.setAdapter(adapter); listView.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { noteDao.deleteByKey(id); Log.d("Dao", "Deleted new note ,Id: " + id); cursor.requery(); return false; } }); }