Close Application Block not working properly

Hello all, I have a problem regarding the Close Application block. When I click the back button on my phone, It should close the application. I did the blocks like this-

When Screen1. Backpressed
  close application

Now when I click the back button, the screen is closed and opens the previously opened screen.

Is that any bug, that is creating a lot of problems for me.
I saw this topic After CLOSE APPLICATION block, app not stopped but there is no reply for that. :pleading_face:

Thank you :smiling_face_with_three_hearts:

1 Like

This is not a bug in app inventor but a problem with not opening and closing screens properly in your app.

Can you say why?

Because you are not closing previously open screens. You open new instances of the same screen.
Insert an aia project, and I'll show you exactly why.

You can use this method to epen another screen:

In place of Screen1, you enter any screen you want to open.

ATL_KV_EKM_Group_4_Prototype_PreProduction1.aia (1.6 MB)
This is the aia please check it

As I wrote above. On many screens I have found blocks that open screens and no block that closes the screen. After using the application for a while, you will have multiple instances of the same screens open until you run out of memory for the application. Also, problems with closing applications that you already noticed.
Remember that once opened, the screen stays open even when you cannot see it. When you open the same screen a second time, you already have two of the same screens open. this causes a lot of problems.

Use the Vknow360 method which closes the current screen and opens the next one at the same time. You can also pass the text to the next screen here.

1 Like

So what is the solution?

Visit the link I have given above. And replace your screen opening blocks with the block from Vknow360.

1 Like

Please wait let me try

You have to make these changes on all screens where you open a screen.

1 Like

Can I use this for Screen1

Yes, screen1 can also be closed. The more that on one of the screens you open screen1.

I implemented the solution you proposed and its working. Thank you for your quick support

I saw this in the help documentation-
App developers should never close Screen1 or use this block to return to Screen1. Use the close screen block instead.

I don't see any reasons why screen1 cannot be closed, nor can I return to screen1 with this method. Tested and with screen1 it also works. So to avoid problems, also apply this to screen1. If you need to, you can test and you will see that it's ok.

Of course you can leave screen1 open. Then wherever you call "screen1" use "close screen".

There are many methods. The most important thing is not to have several of the same screens open.

1 Like

Hello: I have chosen to create several Vertical Arrangements within Screen1, sizing each one of them in percentage to 100% and making them visible or invisible to change them. I don't know if it's correct, but it works for me.

1 Like

Are you trying to say about this :sweat_smile:-
http://ai2.appinventor.mit.edu/reference/other/manyscreens.html

Yes Alpha2020, although I had not read anything about it. That confirms then that I did the right thing.
Thanks for the link.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.