Particle, flashing and losing Wifi

When using my Particle Argon device each time plug the USB into my laptop it always flashes to connect to the Wifi. I do the usual ‘particle device wifi’ command and it always connects.

However, when i write some code and flash the device the wi-fi connection seem to be lost. I have to keep re-connecting the wifi.

Any ideas why it is doing this? Is there a way so it will always remember and connect to my wifi each time it switches on?

Another question is, when i flash the device and power the device off, is this code still on the device? So say its flashed successfully and i power off. If i reconnect to the Wifi, is there any need to re-flash the device?

Apologies for the silly questions i am very new to all of this.

Thanks in advance

Yup, flash is non-volatile storage. What you put in there stays in there till it's replaced with something else.

You can try particle usb setup-done and see whether that solves your WiFi amnesia problem.

You can do the following to set your credentials. You can save multiple credentials, too. Typically, I do this when I am going to move a device to a different location which uses a different ssid and password. I do NOT want to be continuously writing these credentials, though. So, I turn off the block of code and re-flash once completed.

//  setting credentials
if (1 == 2) { //  turn on, flash, turn off and flash again 
    // Connects to a network secured with WPA2 credentials.
    // WiFi.setCredentials(ssid, password);
    WiFi.setCredentials("my second ssid", "my second ssid password");
    //WiFi.setCredentials("my third ssid", "my third ssid password");
    delay(200);
}

As long you don't reset the creds - either via WiFi.clearCredentials() or the MODE/SETUP button - it will remember them without you needing to do anything else.