title: App goes back to first activity if paused and relaunched from launcher icon
body: <p>Basically, whenever I launch a second activity and pause the application and relaunch app by tapping on its icon in launcher, app does not resumes on second activity but goes back to first activity. On top of that, if I pause the app(view in task manager), which app makes shows whole activity again like really fast(talking in milliseconds) and then continues to task manager.</p>
  
  <p><strong>Manifest file</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"
      tools:replace="android:icon"&gt;
      &lt;activity
          android:name=".Activity.MainActivity"
          android:launchMode="singleTask"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".Activity.ReferenceActivity"
          android:configChanges="orientation|screenSize" /&gt; &lt;!-- Find a better solution for orientation change --&gt;
  
      &lt;meta-data
          android:name="preloaded_fonts"
          android:resource="@array/preloaded_fonts" /&gt;
  
      &lt;activity android:name=".Activity.AboutActivity"&gt;&lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>Since you would have noticed launchMode set to "singleTask", there is a reason behind it. My app contains recycler view. Its data is updated from second activity. Without launchMode set to singleTask, recyclerview data is not updated so to update the data I had to relaunch whole app just to see any data change. It is a temporary workaround but I am hoping if someone would help me on this matter as well.</p>
  
  <p>About reycler view not updating, I have asked about that question countless times but never got a solution. Yes, I have gone through probably hundreds of similar problems on stack over flow and none of them work. Please bear in mind that I am beginner in Android development hence I do not have knowledge on advanced things like MvvM, RxJava or live data architecture. </p>
  
  <p>P.S Just so any one gives a solution that I recall my data loader function again somewhere in onStart or on Resume, I have tried that countless times and it does not works. My app is not using fragments or any other advanced stuff just basic activities. Any help is appreciated!</p>
  
  <p><strong>Second activity</strong></p>
  
  <pre><code>class ReferenceActivity : AppCompatActivity() {
  
  private var dbHandler: PediaDatabase? = null
  private var note = UserNotes()
  private var noteExisted: Boolean = false
  private var cardAdapterPos: Int? = null
  private var title: String? = null
  private var text: String? = null
  private var sharingMenuOpened: Boolean = false
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_reference)
  
  
      val toolbarRef: Toolbar = findViewById(R.id.toolbarRefID)
      setSupportActionBar(toolbarRef)
  
      val toolbarTxtView = findViewById&lt;TextView&gt;(R.id.refToolbarTitleID)
      supportActionBar!!.setDisplayShowTitleEnabled(false)
  
      overridePendingTransition(R.anim.slide_in, R.anim.slide_out)
  
  
  
  
      dbHandler = PediaDatabase(this)
      val data = intent
      if (!isNewNote) {
          window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
  
          if (data != null) {
              noteExisted = true
  
              this.cardAdapterPos = data.extras.getInt("cardPosition")
              cardID = data.extras.getInt("cardID")
  
  
              existingNote = dbHandler!!.readNote(cardID)
  
              text = existingNote.noteText
              title = existingNote.noteTitle
  
              refTitleID.setText(existingNote.noteTitle, TextView.BufferType.EDITABLE)
              refTextID.setText(existingNote.noteText, TextView.BufferType.EDITABLE)
              toolbarTxtView.text = "Created: " + existingNote.noteDate.toString()
  
  
  
          }
      } else {
          toolbarTxtView.text = "New note"
  
          window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
      }
  }
  
  override fun onResume() {
      super.onResume()
      sharingMenuOpened = false
  }
  
  
  override fun onPause() {
      super.onPause()
  
      if (!sharingMenuOpened)
          saveNote()
  }
  
  
  override fun onCreateOptionsMenu(menu: Menu?): Boolean {
  
      menuInflater.inflate(R.menu.top_menu, menu)
      val addItem: MenuItem = menu!!.findItem(R.id.add_note_menu)
      val delItem: MenuItem = menu.findItem(R.id.delete_note_menu)
      val shareButton: MenuItem = menu.findItem(R.id.shareID)
  
  
      addItem.isVisible = false
      delItem.isVisible = false
      shareButton.isVisible = false
  
      if (noteExisted) {
          delItem.isVisible = true
          shareButton.isVisible = true
      }
  
      return true
  }
  
  override fun onOptionsItemSelected(item: MenuItem?): Boolean {
  
      if (item!!.itemId == R.id.delete_note_menu) {
  
          val deletionMsg = SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
          deletionMsg.titleText = "Delete this note?"
          deletionMsg.confirmText = "Yes"
          deletionMsg.setCancelable(false)
  
  
  
          deletionMsg.setConfirmClickListener(object : SweetAlertDialog.OnSweetClickListener {
              override fun onClick(sweetAlertDialog: SweetAlertDialog?) {
  
                  dbHandler!!.deleteNote(cardID)
  
  
                  deletionMsg.dismissWithAnimation()
  
                  val successMsg = SweetAlertDialog(this@ReferenceActivity, SweetAlertDialog.SUCCESS_TYPE)
                  successMsg.setCancelable(false)
                  successMsg.titleText = "Note deleted!"
  
                  successMsg.setConfirmClickListener(object : SweetAlertDialog.OnSweetClickListener {
                      override fun onClick(sweetAlertDialog: SweetAlertDialog?) {
  
                          successMsg.dismissWithAnimation()
                          finish()
                      }
  
                  }).show()
              }
          })
  
          deletionMsg.setCancelButton("No", object : SweetAlertDialog.OnSweetClickListener {
              override fun onClick(sweetAlertDialog: SweetAlertDialog?) {
                  deletionMsg.dismissWithAnimation()
              }
          })
          deletionMsg.show()
  
  
  
      }
  
      if (item.itemId == R.id.shareID) {
  
          var sharingTitle: String = title!!.trim()
          var sharingText: String = text!!.trim()
  
          sharingMenuOpened = true
  
          val sharingIntent = Intent(android.content.Intent.ACTION_SEND)
          sharingIntent.type = "text/plain"
          val shareBody: String? = sharingText
          sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, sharingTitle)
          sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody)
          startActivity(Intent.createChooser(sharingIntent, "Share to"))
      }
  
      return super.onOptionsItemSelected(item)
  }
  
  private fun saveNote() {
      title = refTitleID.text.toString().trim()
      text = refTextID.text.toString().trim()
  
  
      if (existingNote.noteText == text &amp;&amp; existingNote.noteTitle == title) {
          finish()
      } else {
  
          if (noteExisted) {
  
              if (TextUtils.isEmpty(title) &amp;&amp; TextUtils.isEmpty(text)) {
                  dbHandler!!.deleteNote(cardID)
  
                  val parsedColor = Color.parseColor("#263238")
                  Toasty.Config.getInstance().setInfoColor(parsedColor).apply()
                  Toasty.info(this, "Note deleted", Toast.LENGTH_SHORT, true).show()
              } else {
  
                  if (TextUtils.isEmpty(title))
                      title = "No title"
  
                  existingNote.noteTitle = title
                  existingNote.noteText = text
                  existingNote.noteDate = System.currentTimeMillis().toString()
  
                  dbHandler!!.updateNote(existingNote)
                  Toasty.success(this, "Note saved", Toast.LENGTH_SHORT, true).show()
  
  
                  startActivity(Intent(this, MainActivity::class.java))
                  finish()
              }
  
          } else {
              if (TextUtils.isEmpty(title) &amp;&amp; TextUtils.isEmpty(text)) {
                  finish()
              } else {
                  if (TextUtils.isEmpty(title))
                      title = "No title"
  
                  note.noteTitle = title
                  note.noteText = text
                  note.noteDate = System.currentTimeMillis().toString()
  
                  dbHandler!!.createNote(note)
                  Toasty.success(this, "Note saved", Toast.LENGTH_SHORT, true).show()
  
  
                  startActivity(Intent(this, MainActivity::class.java))
                  finish()
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>