Application crashes when navigating back on several views really fast and with the activityBackPressedEvent cancelling the back button on first view.
Yes, I've searched and couldn't find anything.
I've created an app with some views and I need to block the back button ONLY on the first view with the activityBackPressedEvent.
Basically I've done this on the navigatedTo function of the first view:
mainPage = args.object;
if(app.android) {
app.android.on(app.AndroidApplication.activityBackPressedEvent, backEvent);
}
And on the backEvent function I've put:
function backEvent(args) {
var currentPage = frameModule.topmost().currentPage;
if(mainPage == currentPage)
args.cancel = true;
}
Basically it works as expected except when I'm on view 5 and click several times on the back button, that's when the app crashes:

Android
Create some views and the navigation between them like View 1 --> View 2 --> View 3 --> View 4 --> View 5 and click on the back button really fast a lot of times. Also, insert the code I've put on the description of my problem in the code of first view.
Already on the description of the problem.
I've also tried to reproduce this issue with NativeScript 2.5.0 and there's no problem at all, it does the action expected.
Hi @pedromareis ,
I tested the described scenario while using NativeScript 3.2.1 and the description from this blog post, however, I was unable to recreate the similar problem. Keep in mind that I registered activityBackPressedEvent inside the app.ts file as it is described on the blog and where it is the right place to do that.
For your convenience, I am attaching GIF file from the simulator and sample project. You can review it and make the needed changes, which will allow us to recreate behavior.
Archive.zip

Hello @tsonevn,
From what I've seen from the gif I guess you're doing the activityBackPressedEvent only on the last view (View 6) instead of doing it on view 1... And even if you remove the event I think you can see the error too when navigating from view 6 to 1 pressing multiple times the back button...
Hi @pedromareis,
In sample project, I disabled the back button in the app.ts file for the whole application inside the callback method for the activityBackPressedEvent.
The scenarios that I tested on our devices are as follows:
The described scenarios could be reviewed in the attached video and by building the attached project on your side.
To be able to investigate further the problem, it would help if you could send us sample project.
Archive.zip
@tsonevn any updates on this?
Hi @pedromareis,
We reviewed your project, however as you could see on the attached GIF file, still the project is built properly and the navigation works as expected. The project was tested on Android simulator API level 23 similar to yours, Could you verify, whether I am missing some step on the attached gif?

@tsonevn well, from what I see in the gif I don't think you're doing it exactly like I did... The problem only occurs if you tap quickly on the back button and multiple times. Could you try that?
Basically I don't even give the app time to process all the taps on the back button and the app eventually crashes because of that.
@pedromareis,
Indeed you are right, to reproduce the problem, the Back button should be tapped quickly multiple times.
I tested this case with the official version and with @next of the modules. Unfortunately, the issue is reproduced with both. Regarding that, I would suggest keeping track on the issue for further info about the case.
Any updates on when will this be fixed?
Hi @pedromareis,
We are working on resolving this problem. We will provide more info in the issue when we have a solution.
@pedromareis This should be fixed in master branch and will be included in 3.4
If possible please try it with @next of tns-core-modules and ping me back if issue is still present.
Hello @hshristov, I've just updated the core modules and everything seems to be okay. Thank you!!
@pedromareis That's great.
Thanks for taking time to verify it. Really appreciate it.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@pedromareis This should be fixed in master branch and will be included in 3.4
If possible please try it with @next of tns-core-modules and ping me back if issue is still present.