Automatically restart an App when it's code is changed?

While writing and testing new/modified Apps it is cumbersome and time consuming to go to the "Apps" menu, than choose my App, than scroll all the way down to hit the "Done" button to finally force a reload of my App (e.g. initialize some internally used vars, subscribes, timers, ...).

Any suggestions to accomplish such a task automatically?

If you store the current version to a state variable, you can now compare last saved to current version.

This requires that you have code paths that run regularly (think some timer event or device event), so that this regularly running code on the next execution after a code update would find the change and do whatever initialization you want (and it is a real event, process the event)

I'm not aware of an application event for 'code reload'.

This has been asked a few times before and you are correct (as always). :slight_smile:

As an alternative to the above, if it's your own app and you just need to do this on occasion, you could provide an easy way to do this yourself, like a button (an input type in Hubitat) that runs a method when pressed or a dynamicPage (I think it has to be dynamic...) you could bookmark that just runs some method when loaded, though both are still basically manual.

@nh.schottfam, @bertabcd1234: Thanx for your ideas!

It's a pity that there is no such "code reload" event.

At the moment my "solution" (if you want to call an ugly workaround that) is this:

I use a field static variable to detect, if my init routines are all run, e.g.:
@Field static boolean isInitialized = false

And in my init routine I set this var to true:
private void initialize() {
if (isInitialized) return
// subscribe ...
// schedule ...
// set global variables ...
isInitialized = true
}

The problem is, that I have to call initialize in every method which needs one of those initialized objects... :roll_eyes:

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