Why do loops crash?

Sure! Good to know that.......

Just use a clock timer with an if/else statement....

1 Like

Tried that but I made it a bit messed up :grimacing: :grimacing: Can anyone help me make it?

Again, post your blocks. We can't guess what you are trying to do.
If you start an infinite loop, App Inventor will freeze and become unresponsive. That's why the app closes itself.
There's no need to create an infinite loop in App Inventor. Like @TIMAI2 suggested, you need to use a clock for that.

2 Likes

Here

Will it be fine if I make a loop using procedure blocks?

I think it's the bugs :

2 Likes

@Salman_Dev the loop is working but i am unable to control my BPM now

I think this "Loop" topic is related to your "Metronome" topic. So please merge these.

Here you get some suggestions, especially from @ABG. You will find that this is by no means as trivial as it initially seems.
https://groups.google.com/g/mitappinventortest/c/2SoKmgGVYvI/m/vtakqWbsFQAJ

See my last sentence as an appreciation to @ABG :
"Thank you for your amazing work. After this crash course with you I will probably be able to prepare students for the math exam." :wink:

In the end - mainly because of the inaccuracy of the Clock component and the fact that the timer does not work in the background on many devices - I took a completely different path.

Note:
Of course there are some approaches to bypass the inaccuracy of the clock (e.g. that of Scott Feguson), but even that does not solve all problems.

In order for the timer to work also in the background (idle / sleep mode, screen off, Doze), you need a Foreground service (which has been possible in AI2 since the nb184 release).
Even REQUEST_IGNORE_BATTERY_OPTIMIZATIONS doesn't help.

The same applies to the Clock.
Otherwise you have to keep the screen alive (→ KeepScreenOn, TaifunTools ext.) or connect the device to the charging cable.

OK, thank you but the app works well in the background. The actual problem is that because I am using the clock component I am unable control the interval between the ticks. Also that the timer interval's minimum value is limited to 4 digits I cannot go less than that neither can I use decimal values.

In simple words, I cannot type like this "0008333" or "8.333"

As I already said, definitively not on all devices (e.g. Samsung Galaxy Note8, S8 → Android 9, ...).

OK, it worked in Android 7. That's what I use.

If the app is only intended for your own use, then everything is fine.

Hello There!
I am making a Metronome App because I find there are too much of ads and pretty less room for customization in others. I need 2 things:-

  1. A sound effect for a metronome.
    AND
  2. A loop that won't crash (while loops crash when they are set to infinite).

You created another topic for this same problem:

I'm closing this one.

2 Likes

Why is a wait procedure generally a bad idea?

The model of event processing in App Inventor by @Franklyn_A_Turbak

Please Wait method

All about Loops from the old Forum

and in this Community (Loops)

Regarding the original post of how to run an infinite loop. the general idea is to use a global list as a work queue, driven by a fast Clock Timer.

Here are some projects that run forever like that ...
http://ai2.appinventor.mit.edu/?galleryId=5214268554739712 (Sierpinski Triangle)
ai2.appinventor.mit.edu/?galleryId=6477875229491200 (sieve of Eratothsenes)
https://docs.google.com/document/d/1JrSnPo-7i2l_am4cHC6TgcpKhQVslZowSW4ooWDc7ww/edit?usp=sharing

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