且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在后台运行应用程序?

更新时间:2023-02-19 19:09:10

一般的答案是,你不能在后台运行你的应用程序,除了某些情况。



Doc说,


此后不久,大多数进入后台状态的应用程序都会被移至暂停状态。处于此状态时,应用程序不会执行任何代码,并且可能随时从内存中删除。为用户提供特定服务的应用程序可以请求后台执行时间以提供这些服务。


所以只有一些特定的服务,如 audio,location和voip 服务可以在后台执行。阅读 在后台执行代码 doc,了解有关后台服务的更多详细信息。


Iam doing one application.In that i want to run the my application in the background.So how to write the code for that.Please tell me because iam very new for this technology.

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.