Help us understand the problem. What is going on with this article?

在 Android 中避免打開登入畫面後,按系統的返回鈕可以把登入頁面關掉

More than 3 years have passed since last update.

問題

有一個 MainActivity 為主畫面,
當使用者沒有登入的時候,會透過 Intent 在上面疊一個 LoginActivity
接著按下系統的返回按鈕會回到 MainActivity

預期

在 MainActivity 是被設定成要登入才可以觀看這樣的先決條件之下,
當 LoginActivity 出來之後,按返回鍵應該是會回到手機的桌面去

解決辦法

在 LoginActivity 裡面,加上一個 callback 實作即可:

override fun onBackPressed() {
    moveTaskToBack(true)
}

參考

vc7
iOS Developer from 🇹🇼
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした