The general answer is, you can not run your application while in background, except certain cases.
Doc says,
Most applications that enter the background state are moved to the suspended state shortly thereafter. While in this state, the application does not execute any code and may be removed from memory at any time. Applications that provide specific services to the user can request background execution time in order to provide those services.
So only some specific services like audio, location and voip services can execute in background. Read this Executing Code in the Background
doc for more detail regarding the background services.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…