My coding skills are not enough for this. I'd rather cancel any macro on thisFirstly follow steps at dontkillmyapp.com for your app.
Then the only way to check your app is running is to check if it is in foreground. There's a trigger for application open/closed and magic text for foreground app package or app name. You just compare it to the name of the network monitor app.