Android Question how to debug this? Sleep(0) vs DoEvents

peacemaker

Expert
Licensed User
Longtime User
HI, All

App user informed me that the latest version is stopped after some time.
After some test i have found that after 360 seconds ALWAYS app is stopped with such error, even in the Debug mode:



It seems to me that it is some timer tick sub and isPaused function. But i cannot find such function usage in all timers subs.
App is old, and i found that DOEVENTS is still used, but not all places, some are already with Sleep(0) instead.

And when i placed DOEVENTS everywere instead of Sleep(0) .... hanging is over, app works fully OK.
When to use Sleep(0) - it's again error.

How to understand it ?
 

agraham

Expert
Licensed User
Longtime User
The error is occurring when the Timer is trying to invoke your Timer Sub. It seems to be finding that the ba object is null.
Java:
    public void run() {
      Timer parentTimer = this.parent.timer;
      if (parentTimer == null || this.currentTimer != parentTimer.relevantTimer)
        return;
      BA.handler.postDelayed(this, parentTimer.interval);
      if (!this.ba.isActivityPaused() && !Msgbox.msgboxIsVisible()) // <--------------This is line 104
        this.ba.raiseEvent2(parentTimer, false, parentTimer.eventName, true, new Object[0]);
    }
  }
Is your Timer in the Starter service, it looks like it, or in another Service? As it is an old app it looks like some behaviour in Android has changed in later versions.

DoEvents and Sleep behave differently. DoEvents executes some of the messages on the app message loop without returning to the message loop then continues in your Sub. Sleep actually returns to the app message loop and then your Sub is re-entered some time later. Because DoEvents executes the messages itself it has become very fragile over the years as the message loop code has become more complicated and is now deprecated.
 
Upvote 1

peacemaker

Expert
Licensed User
Longtime User
or in another Service
Yes, timer in a separate foreground service with a notification. All the time it was tested under Android 12.
How to be here ?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…