From d55b3282d7c01ba34c6ace9799021e54c714e057 Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Tue, 22 Feb 2022 18:44:27 +0100 Subject: [PATCH] Fixed unnecessary note creating on app resume --- .../notes/pro/activities/MainActivity.kt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt index 9e61b798..174ba2fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/MainActivity.kt @@ -338,20 +338,25 @@ class MainActivity : SimpleActivity() { if (action == Intent.ACTION_VIEW) { val realPath = intent.getStringExtra(REAL_FILE_PATH) - if (realPath != null && hasPermission(PERMISSION_READ_STORAGE)) { - val file = File(realPath) - handleUri(Uri.fromFile(file)) - } else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) { - val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "") - addNewNote(newTextNote) - } else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) { - val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "") - addNewNote(newChecklist) - } else { - handleUri(data!!) + val isFromHistory = intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY != 0 + if (!isFromHistory) { + if (realPath != null && hasPermission(PERMISSION_READ_STORAGE)) { + val file = File(realPath) + handleUri(Uri.fromFile(file)) + } else if (intent.getBooleanExtra(NEW_TEXT_NOTE, false)) { + val newTextNote = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_TEXT.value, "", PROTECTION_NONE, "") + addNewNote(newTextNote) + } else if (intent.getBooleanExtra(NEW_CHECKLIST, false)) { + val newChecklist = Note(null, getCurrentFormattedDateTime(), "", NoteType.TYPE_CHECKLIST.value, "", PROTECTION_NONE, "") + addNewNote(newChecklist) + } else { + handleUri(data!!) + } } intent.removeCategory(Intent.CATEGORY_DEFAULT) intent.action = null + intent.removeExtra(NEW_CHECKLIST) + intent.removeExtra(NEW_TEXT_NOTE) } } }