android 如何只关闭最后打开的Activity而不是所有Activity?

ioekq8ef  于 5个月前  发布在  Android
关注(0)|答案(1)|浏览(56)

我构建了一个无线电应用程序,其中用户可以打开一个NowPlaying屏幕,并从该屏幕打开另外两个屏幕。当我从最后一个屏幕调用完成时,NowPlaying屏幕也会关闭。请参阅此视频:https://youtube.com/shorts/dsgxC9t0svQ
如何才能只关闭一个屏幕,让用户返回到正在播放屏幕?
要打开"正在播放“屏幕,我用途:

nowPlayingBtn.setOnClickListener {

    runOnUiThread {

        val intent = Intent(this@MainActivity, NowPlaying::class.java)
        startActivity(intent)

    }

}

字符串
要打开“刚播放”屏幕,我用途:

binding.justPlayedButton?.setOnClickListener {

    runOnUiThread {
  
        val intent = Intent(this@NowPlaying, JustPlayed::class.java)
        startActivity(intent)

    }

}


要关闭屏幕,我用途:

binding.terugBtn.setOnClickListener {

     finish()

}


此代码添加到两个Activity中:NowPlaying和JustPlayed。
我在两个屏幕上都使用了这个绑定。当我在JustPlayed屏幕上按下“terug”(返回)按钮时,只调用那个。它不会同时调用两个“terug”动作。我测试了一下。
当我按下“现在播放”屏幕上的“terug”按钮时,只调用该按钮。
我在开始屏幕中使用noHistory:

<activity
     android:name=".Start"
     android:exported="true"
     android:noHistory="true">
     <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
     </intent-filter>
</activity>

eaf3rand

eaf3rand1#

我在代码中有两次finish():一次在“terug”按钮上,一次在onStop()函数上。

相关问题