Skip to content

Commit

Permalink
Replace deprecated onBackPressed call
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 523361561
(cherry picked from commit be85684)
  • Loading branch information
tonihei authored and rohitjoins committed Apr 18, 2023
1 parent 8aec88b commit 0690c9b
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.media3.common.MediaItem
Expand Down Expand Up @@ -73,21 +74,24 @@ class MainActivity : AppCompatActivity() {
val intent = Intent(this, PlayerActivity::class.java)
startActivity(intent)
}

onBackPressedDispatcher.addCallback(
object : OnBackPressedCallback(/* enabled= */ true) {
override fun handleOnBackPressed() {
popPathStack()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
onBackPressed()
onBackPressedDispatcher.onBackPressed()
return true
}
return super.onOptionsItemSelected(item)
}

@SuppressWarnings("MissingSuperCall")
override fun onBackPressed() {
popPathStack()
}

override fun onStart() {
super.onStart()
initializeBrowser()
Expand Down

0 comments on commit 0690c9b

Please sign in to comment.