How to make counter still counting after application has quit?

just like the building worker in clash of clan
the counter still work when the app is closed
.how to achieve that???

I guess you want to do something like those game that keeps track of time even though you are not playing.

Well, the game is not running, the game stores the time you quit and stores only that.
When you come back, the game compares what time it is now and what time was it when you left. Then depending on that time, it applies various changes.

In order to get the time you use the DateTime structure.

you could have a time based variable that is saved when you quit the app, and then when you reload the app you can calculate how much time has passed since it was closed, then run your simulation based on the amount of time that has passed.

So it takes 1 day to build a house, you start building a house then quit the app at 07.00, then you reload it at 19.00, when you reload the app you calculate that 12 hours have passed, this would mean that your house is 50% complete, you can then alter the current state of the building to 50% complete. there may be another way to do it.