File tree Expand file tree Collapse file tree 1 file changed +20
-10
lines changed
app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/android/lessons/data/room Expand file tree Collapse file tree 1 file changed +20
-10
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,15 @@ protected void onCreate(Bundle savedInstanceState) {
5252 binding .buttonAdd .setOnClickListener (v -> {
5353 String text = String .valueOf (binding .editTextNote .getText ()).trim ();
5454 if (!text .isEmpty ()) {
55- executor .execute (() -> {
56- db .noteDao ().insert (new Note (text ));
57- runOnUiThread (() -> {
58- binding .editTextNote .setText ("" );
59- loadNotes ();
55+ if (!executor .isShutdown ()) {
56+ executor .execute (() -> {
57+ db .noteDao ().insert (new Note (text ));
58+ runOnUiThread (() -> {
59+ binding .editTextNote .setText ("" );
60+ loadNotes ();
61+ });
6062 });
61- });
63+ }
6264 }
6365 });
6466
@@ -68,10 +70,18 @@ protected void onCreate(Bundle savedInstanceState) {
6870 }
6971
7072 private void loadNotes () {
71- executor .execute (() -> {
72- List <Note > notes = db .noteDao ().getAll ();
73- runOnUiThread (() -> adapter .setNotes (notes ));
74- });
73+ if (!executor .isShutdown ()) {
74+ executor .execute (() -> {
75+ List <Note > notes = db .noteDao ().getAll ();
76+ runOnUiThread (() -> adapter .setNotes (notes ));
77+ });
78+ }
79+ }
80+
81+ @ Override
82+ protected void onDestroy () {
83+ super .onDestroy ();
84+ executor .shutdown ();
7585 }
7686
7787 private static class NotesAdapter extends RecyclerView .Adapter <NotesAdapter .NoteViewHolder > {
You can’t perform that action at this time.
0 commit comments