To obtain a patent, the invention should not be available in the public domain prior to filing a patent application.
However, the scenario is different in USA, in United states one can file for a patent within 1 year grace period after the invention has been disclosed in the public domain.
Secondly, one can sell an app immediately once it is filed. Although there are various stages involved for granting a patent, but this stages do not restrict for commercial exploitation of the app. It shall be noted that a commercializing the app after filing will not act as a prior art to invalidate the patent application.