diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 230455575..24d3cb609 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,9 @@ android:resource="@xml/shortcuts" android:launchMode="singleTask" /> - + > = arrayListOf() + fun size(): Int { + LogUtils.d("xxxx", activities.size.toString()) + return activities.size + } + /** * 判断指定Activity是否存在 */ diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 6636eb64b..ebd4b73a7 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -12,6 +12,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.constant.Bus +import io.legado.app.help.ActivityHelp import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert @@ -103,22 +104,12 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), return super.onKeyUp(keyCode, event) } - private inner class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : - FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { - - override fun getItem(position: Int): Fragment { - return when (position) { - 0 -> BookshelfFragment() - 1 -> ExploreFragment() - 2 -> RssFragment() - else -> MyFragment() - } - } - - override fun getCount(): Int { - return 4 + override fun finish() { + if (ActivityHelp.size() > 1) { + moveTaskToBack(true) + } else { + super.finish() } - } override fun observeLiveBus() { @@ -127,3 +118,20 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), } } } + +private class TabFragmentPageAdapter internal constructor(fm: FragmentManager) : + FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { + + override fun getItem(position: Int): Fragment { + return when (position) { + 0 -> BookshelfFragment() + 1 -> ExploreFragment() + 2 -> RssFragment() + else -> MyFragment() + } + } + + override fun getCount(): Int { + return 4 + } +}