Blame MD or Android

OscariBot

Active member
I'm really wondering how macrodroid or maybe android handle notifications...

For some time now I have been using notification listener plugin to respond to my business telegram messages... But something strange happened yesterday (maybe it has been happening without my knowledge)
When I got more than 1 notification mayb few milisec interval apart, the macro get confused and either ignore the first notification or sometimes respond to the second notification with a response that was meant for the first notification. (This means it sometimes process the first notification but the result is sent to the second notification)

I was expecting first come first serve kind of thing were this notifications are queue and process one at a time.

Is notification supposed to override?
Why is my macro confused?
Who is to be blame MD or Android?
Could the plugin be the culprit?

I just don't get it.
 

FrameXX

Well-known member
I don't know exactly what all your macro does before responding the message, but it is possible that if the macro is triggered once and then a second time quickly afterwards, the second execution can manipulate variables that the first execution is still working with and this can cripple the execution all together.

What I advise you to do is to put all the actions, or at least a larger portion of the actions (the more execution done in the action block the better) of the macro into one action block. This may sound strange at first, but I have to point out that each action block runs in its own isolated thread (as I've said before on this forum) and so should not interfere with executions running in parallel, which can happen in your case where the processing time of the macro can be longer than the time until the next notification arrives and therefore 2 executions of the macro happen to run simultaneously.
 

OscariBot

Active member
This really make sense to me... Hang on I shall give it a shot right away.

I shall be back with perhaps positive result
 

Endercraft

Moderator (& bug finder :D)
each action block runs in its own isolated thread
I can confirm that. One of my macros displays floating text and uses an action block to display each floating text (coming from a variable) without having the same value displayed. What's interesting is that after the action block stops the value is still displayed instead of losing it's value and displaying something like [lv=show] instead.
 

Dm114

Well-known member
I can confirm that. One of my macros displays floating text and uses an action block to display each floating text (coming from a variable) without having the same value displayed. What's interesting is that after the action block stops the value is still displayed instead of losing it's value and displaying something like [lv=show] instead.
This is due to Floating text feature (not to Action block) as I explained in a previous thread a few days ago...
 

OscariBot

Active member
I don't know exactly what all your macro does before responding the message, but it is possible that if the macro is triggered once and then a second time quickly afterwards, the second execution can manipulate variables that the first execution is still working with and this can cripple the execution all together.

What I advise you to do is to put all the actions, or at least a larger portion of the actions (the more execution done in the action block the better) of the macro into one action block. This may sound strange at first, but I have to point out that each action block runs in its own isolated thread (as I've said before on this forum) and so should not interfere with executions running in parallel, which can happen in your case where the processing time of the macro can be longer than the time until the next notification arrives and therefore 2 executions of the macro happen to run simultaneously.
Action Block didn't solve the problem...

I was actually using local variables to process each entry to avoid overriding data on arrival of next notification.
This issue remain unchanged even with with Action block.

I sense that the challenge is actually on the input and output variable since they are global.
On arrival of a new notification it overrides the data in the input variable hence disrupting the processed data of the first notification.

I observed that the only way to stop this is to somehow queue notifications but how?
 

Dm114

Well-known member
Action Block didn't solve the problem...

I was actually using local variables to process each entry to avoid overriding data on arrival of next notification.
This issue remain unchanged even with with Action block.

I sense that the challenge is actually on the input and output variable since they are global.
On arrival of a new notification it overrides the data in the input variable hence disrupting the processed data of the first notification.

I observed that the only way to stop this is to somehow queue notifications but how?
As far as I understand your problem, instead of running actions according to the received notifications, you could store each of them (from index 0 to array_size-1) in an array as they arrive to prevent from missing some of them.
Then, in a loop (if macro is not currently running), While array_size>0 do whatever you have to do.
Don't forget to Delete array key you just dealed with and set to False your "running indicator" when you finish iterating the whole array.
 

OscariBot

Active member
As far as I understand your problem, instead of running actions according to the received notifications, you could store each of them (from index 0 to array_size-1) in an array as they arrive to prevent from missing some of them.
Then, in a loop (if macro is not currently running), While array_size>0 do whatever you have to do.
Don't forget to Delete array key you just dealed with and set to False your "running indicator" when you finish iterating the whole array.
This sound like a solution 🤗
I will be back on this.

Thanks
 

Dm114

Well-known member
Oh thanks...
Am already on it...

Sounds promising..😘
Sorry I made a mistake: the MacroRunning=False has to be placed before the last Endif statement, not at the very end of the macro
 

Attachments

  • IMG-20230408-WA0006.jpg
    IMG-20230408-WA0006.jpg
    79.2 KB · Views: 14
Last edited:

OscariBot

Active member
Ok @Dimlos ... It seems your macro will ignore any notification that arrived wen the macro is already running it loop with notification size.

I don't want any notification to be ignored. Am trying to modify it .
 

Dm114

Well-known member
Ok @Dimlos ... It seems your macro will ignore any notification that arrived wen the macro is already running it loop with notification size.

I don't want any notification to be ignored. Am trying to modify it .
Who are you answering to: Dimlos or me?

With my macro, you'll never miss any notification.
 

OscariBot

Active member
Am just wondering wat will happen if notification arrived wen the macro is already running...

But it's good I test it to the fullest... Am sending random notice to see how potent it is...

Thanks
 

Dm114

Well-known member
Am just wondering wat will happen if notification arrived wen the macro is already running...

But it's good I test it to the fullest... Am sending random notice to see how potent it is...

Thanks
Test it but the principle is to store every incoming notification in the array called "Notifications", whether the macro is running or not: there is no constraint.
 
Top