处理导航后退按钮

时间:2019-09-01 16:38:53

标签: android android-fragments kotlin

我有两个片段,public function simpan_data($data_pickup){ $this->simpan_pickup($data_pickup); $last_key = $this->db->insert_id(); $tmp = $this->get_temporary(); foreach($tmp as $t){ $qty_pickup = $this->input->post('qty_pickup_new')[$t->id_barang]; // using id_barang as qty_pickup_new[] key $data_detail = array( 'id_pickup' => $last_key, 'id_barang' => $t->id_barang, 'qty_pickup' => !empty($qty_pickup) ? $qty_pickup : '' // sets data as empty if input is empty ); $this->db->insert('pickup_detail', $data_detail); } } A。片段B启动A

B

现在在片段findNavController().navigate(R.id.action_A_to_B) 中,我在UI上有一个按钮可以返回片段B。我应该如何使用NavController做到这一点?我应该只在导航中创建一个动作吗?还是我可以做一些可以返回给呼叫者的事情?

我问,因为添加一个动作意味着图中的AA -> B看起来有点奇怪。

1 个答案:

答案 0 :(得分:0)

您只需要获取NavController并调用popBackStack()即可再次从堆栈中删除片段B

findNavController().popBackStack()