I have an issue on a SUNMI P2 terminal that has integrated NEXO protocol and Besteron for payment. To process the payment a HTTP request is sent from my app to the NEXO API which then displays the Besteron's UI that tells the user to use a card. When the the card is read, this Besteron UI stays in the front instead of redirecting the user back to my app.
Android version 11
I send a HTTP request to the NEXO protocol and when I get the response the paymentResult.collect triggers. Inside the collect I try to bring my app back to the front using Intent.FLAG_ACTIVITY_REORDER_TO_FRONT, but it does not work. Then I call the doTransactionTickets which calls my API which then triggers the transactionResult.collect which just navigates to another page.
The app has one MainActivity and multiple fragments, the following code is inside CheckoutFragment.kt
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) { viewModel.paymentResult.collect { Log.d("paymentTest", "The payment response has been received: $it") val intent = Intent(requireActivity(), MainActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT } requireActivity().startActivity(intent) viewModel.doTransactionTickets ( binding.noteText.editText?.text.toString(), args.itemType, args.itemId, args.selectedTickets!!.tickets, totalPrice.formatWithDecimalPlaces(), args.date, args.packItems?.result, args.itemSeats, client ) } } } viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.CREATED) { viewModel.transactionResult.collect { item -> val receipt = viewModel.receiptPdf.value?.let { PdfDocument(it) } val ticket = viewModel.ticketPdf.value?.let { PdfDocument(it) } Log.d("paymentTest", "Transaction done") requireActivity().runOnUiThread { findNavController().navigate( R.id.action_checkoutFragment_to_confirmationFragment, Bundle().apply { putString("name", args.name) putFloat("totalPrice", totalPrice.toFloat()) putString( "ticketsDescription", binding.summaryTicketBreakdown.text.toString() ) putString("eventDateTime", args.date) putString("orderNumber", item.toString()) putInt("itemType", args.itemType) putBoolean("hasTimetable", args.hasTimetable) putSerializable("receipt", receipt) putSerializable("ticket", ticket) } ) } } } }
What else can I do here, I am open to ideas.
This can happen if the payment screen is opened as a separate activity. After the transaction finishes, Android may keep that activity on top, so your app doesn’t automatically return to the foreground. Instead of navigating to a fragment inside Collect, try bringing your main activity back explicitly when you receive the result. You can start your activity again with flags such as
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or Intent.FLAG_ACTIVITY_SINGLE_TOP.
This usually brings the existing activity to the front instead of creating a new one. It’s also worth checking the NEXO/Besteron documentation to see if they provide a callback or return intent after the transaction. Many payment SDKs expect you to handle that event to bring the app back to the foreground rather than doing the navigation manually.