我有viewpager选项卡片段,并从按钮上的一个tabb片段单击它打开另一个片段,另一个片段我想添加后备事件,因为我做backpress它退出应用程序,因为我在我的根片段写的双背压退出代码代码,我不想这个代码在我的另一个第二个片段打电话,因为我想简单地一步一回头我以前的片段 由于这里是代码片段从第二个片段返回堆栈到第一个片段
R.id.Recharge -> {
val pl = Payment_History()
fragmentTransaction = fragmentManager!!.beginTransaction()
fragmentTransaction.replace(R.id.frame_container, paypal)
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
}
在付款历史中,我打电话回来按压覆盖功能
override fun onBackPressed(): Boolean {
super.onBackPressed()
}
并点击Paymenthistory它从应用程序中调用退出代码。我希望它回到以前的片段。正如我写的这个片段代码,但不工作。 任何人都有想法如何将第二个嵌套片段备份到以前的片段。
我在我的MainActivity
override fun onBackPressed() {
// TODO Auto-generated method stub
try {
if (getFragmentManager().getBackStackEntryCount() == 0) {
if (doubleBackToExitPressedOnce) {
//super.onBackPressed();
val startMain = Intent(Intent.ACTION_MAIN)
startMain.addCategory(Intent.CATEGORY_HOME)
startMain.flags = Intent.FLAG_ACTIVITY_NEW_TASK
pref!!.setLoggedIn(true)
startMain.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
startMain.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
startActivity(startMain)
return
}
this.doubleBackToExitPressedOnce = true
Toast.makeText(this, "Please click again to exit", Toast.LENGTH_SHORT).show()
Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
}
}catch (e:Exception){
println("homemessage"+ e.message)
}
}
这是行不通的。因为它再次提供退出应用程序的退出选项 – Jyoti