mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Replace deprecated onBackPressed call
PiperOrigin-RevId: 523361561
This commit is contained in:
parent
e4bb1045ef
commit
be85684dc9
@ -26,6 +26,7 @@ import android.view.ViewGroup
|
|||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
@ -73,21 +74,24 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val intent = Intent(this, PlayerActivity::class.java)
|
val intent = Intent(this, PlayerActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(
|
||||||
|
object : OnBackPressedCallback(/* enabled= */ true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
popPathStack()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == android.R.id.home) {
|
if (item.itemId == android.R.id.home) {
|
||||||
onBackPressed()
|
onBackPressedDispatcher.onBackPressed()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("MissingSuperCall")
|
|
||||||
override fun onBackPressed() {
|
|
||||||
popPathStack()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
initializeBrowser()
|
initializeBrowser()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user