Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@vc7

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

問題

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

預期

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

解決辦法

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

override fun onBackPressed() {
    moveTaskToBack(true)
}

參考

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
0
Help us understand the problem. What are the problem?