Apk crashes but ai companion works without issue

See these tips too:

ProfessorCad: Tips & Tricks GUI Layout and Component Naming

ProfessorCad: Tips & Tricks Cannot Build/Install/Run APK

Hello ,while i look for those. could you suggest

  1. how to check for the response of write permission?
  2. what would be the proceedure doing at the last line of screen initialiase?
  3. how to disable the clock timers?

Why are you asking for write permission when not writing a file? Is a file written via another Screen? If so, the permission should really be requested on App launch, from Screen1.

You call the procedure from the last line - in fact, if you do need write externally:

You already know how:
Snap1

Edit: So you can do this, use one Procedure to disable the Timers and open the required screen:

Snap2

Is this actually your code?

yes i did all in many months .. i have a background in programming so the logic part was clear to me. just im revisiting after a break of few months so not very clear of blocks.. i think you too would be in the same boat :slight_smile:

The only thing that can cause your app to crash is extensions. So I suggest removing extensions one by one and checking if the apk works.

Hence my tips about naming, so that everything is easier to follow (also with copious amounts of inline notes).

Alright, it has been observed the apk is crashing after the first line, when the write external storage is called. anyway how we can over ride it?

You mean how can it be fixed?

First need to know:

  1. Is the App only for your use (not going to be distributed to others)
  2. If so what is the exact Android Version of your device (phone).

The issue will be the Google security measures that have been introduced over the past two years.

If the App is distributed, then all applicable security measures across all late Android versions must be taken into account.

If it's only for your use then only the applicable security measures that affect your version of Android need to be considered.

There are things you could do to make your App more robust. Firstly, Screen1 should be 'Home', it is the 'King' of the screens so far as Android is concerned.

Secondly, you might consider using virtual screens - sharing the same memory allocation and therefore no need to pass data between screens, no duplication of code or temporary data storage and no danger of causing the App to crash by switching screens incorrectly or leaving a clock timer on.

hello first of all, this is for me only and and my parents
secondly as i mentioned earlier, its on realme ui 3.0 running on android 12

finally, i was not able to make the screen 1 set as home and i had created home screen by mistake. How to transfer the contents of the home screen to make it more like how you have suggested? or can we create a new one and import screen blocks and components?

Sorry, i didnt understand the virtual screen concept. any example or reference would be really helpful
Thanks again.

1 Like

Here we go:

When we define virtual screens, we use one 'real' App Inventor Screen (most often Screen1). Screen-sized Vertical Arrangements on it are displayed/hidden as required - they are the Virtual Screens. This is generally a better approach for multi-screen Apps, they share data without having to "pass" it between screens and it also reduces code duplication, making the App more efficient and the code easier to follow if you have to return to it at a later date.

So, instead of separate "houses", virtual screens are "rooms" of the same "house".

1 Like

SteveJG's example in the tutorial is the way to go if the user is to be presented with buttons/tabs to change screens but of course the code can change screens automatically if required.

You have not mentioned Android 12 in this Topic, you wrote it as "android version in phone is 12" - so my search of the page did not find the info -oh the wonders of the internet. :upside_down_face:

Android 12/13 have the most strict security measures and they affect file handling among other things. Here is an overview by Power User Anke that you need to study:

Although you have requested write permission:

  1. Should be done from Screen1 to give the whole App permission
  2. The folders/directories you can use remain limited

My kind friend i got most of your recommendations, and i would definitely go through them. Thank you again :slight_smile:

Now, can you also suggest, if possible, what's the best way to migrate this project into a new app where i can use the existing code blocks and designers build screen 1 as home without doing everything again?

OK -

  1. back-up your Project!

Export Project

  1. Empty the Backpack (right-mouse on the icon for menu), then (right mouse in the Blocks work area for menu) 'Copy all Blocks to the Backpack'.

  2. To copy screen 'Home', in the Designer (not the Blocks), pick 'Home' in the Components palette, then use keyboard Ctrl+C to copy to the Windows Clipboard.

  3. Create a new Project with a different name, then Ctrl+V to paste.

If converting to Virtual Screens, create a Virtual Screen first (Screen sized Vertical Arrangement, height and width 'fill parent') then paste - the whole GUI should arrive below the new Vertical Arrangement, you will need to drag the components into the Vertical Arrangement.

We should be able to use Ctrl+Shift+V to avoid pasting the component related Blocks, but unfortunately that isn't working, so next step:

  1. Right mouse in the Blocks work area for menu and select 'Delete 123 Blocks' - that will delete all the Blocks and you will get a pop-up to confirm that was your intention. You will then get a pop-up moaning about there not being any Blocks - just click on 'Save the empty screen now'.

  2. Right mouse in the Blocks work area for menu and select 'Paste All Blocks from Backpack (123)'

  3. Empty the Backpack (right-mouse on the icon for menu).

  4. Save the new Project.

Note that if converting to Virtual Screens, some of the existing code is no longer required. So you might want to make a copy of the original file:

..... then butcher that copy (delete the unwanted code) and then use it for copying via Windows clipboard to the new Project, as per the instructions above.

I just noticed that you are using a Table Arrangement. That should be replaced with Horizontal Arrangements as it is a rogue component that can cause corruption.

In my case i did not needed the app storage write permission, so removing it solved my issue. Apologies for my ignorances.

1 Like

That's good to know Shariq. The Google security changes have caused a lot of confusion!

1 Like

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