Save the value of a variable after the app is closed

I have a counter and i would like to save the value of it after the app is closed. I appreciate if someone can help me or post some documentation about this topic.

You can’t do anything AFTER the app is closed/suspended/stopped.
 
Do you mean you want the value to be saved while the app is running and be re-loadable on the next run?
 
If you want to save a value as you shutdown or suspsend:
 
 

  1. Choose your method of saving/storing:
  1. Use the system event to detect when (applicationSuspend) to save:
    https://docs.coronalabs.com/api/event/system/type.html
     
  2. Use the same event to restore, but either on the ‘applicationStart’ or ‘applicationResume’ event.

3a. Alternately do loads in main.lua or a module upon startup and initialization.

Note: Besides the many examples/demos that come with Corona, one of which may cover this concept, I also have many answers on my git:

https://github.com/roaminggamer/RG_FreeStuff

See the AskEd folder generally, and one of these folders for something similar to what you seem to be asking for:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/persistingData

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/persistentCounter

(There may be other answers that help in other years and months.)

Warning: Examples may use SSKand my table.* extensions to save and restore JSON encoded tables.  

I also have io.* extensions for raw file reads and writes.

Lastly, SSK provides a module called persist.* specifically designed to simplify persistent storage of data which memory caching and delayed writes to save battery usage by reducing ‘disk’ accesses to a minimum.

You can’t do anything AFTER the app is closed/suspended/stopped.
 
Do you mean you want the value to be saved while the app is running and be re-loadable on the next run?
 
If you want to save a value as you shutdown or suspsend:
 
 

  1. Choose your method of saving/storing:
  1. Use the system event to detect when (applicationSuspend) to save:
    https://docs.coronalabs.com/api/event/system/type.html
     
  2. Use the same event to restore, but either on the ‘applicationStart’ or ‘applicationResume’ event.

3a. Alternately do loads in main.lua or a module upon startup and initialization.

Note: Besides the many examples/demos that come with Corona, one of which may cover this concept, I also have many answers on my git:

https://github.com/roaminggamer/RG_FreeStuff

See the AskEd folder generally, and one of these folders for something similar to what you seem to be asking for:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/persistingData

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/07/persistentCounter

(There may be other answers that help in other years and months.)

Warning: Examples may use SSKand my table.* extensions to save and restore JSON encoded tables.  

I also have io.* extensions for raw file reads and writes.

Lastly, SSK provides a module called persist.* specifically designed to simplify persistent storage of data which memory caching and delayed writes to save battery usage by reducing ‘disk’ accesses to a minimum.