问题
I know about the Windows Phone 8.1 Applications lifecycle: http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff817008%28v=vs.105%29.aspx
But, is it possible to keep active the application when it is not used (after deactivation)?
Is it possible to realize a WP8.1 App that sends some data to a Server at predetermined time intervals? Is it possible to execute code in the App, when it is deactivated?
回答1:
As you have tagged your question for WP8.1, apart from Silverlight apps, there are also Universal/Runtime apps. It's worth to mention that in Windows Phone 8.1 Runtime Apps you have a little different app lifecycle.
Any way, when your App is being Suspended, Deactivated, Tombstoned or put into Not-Running state, it is being stopped. and there is no way that it will work in Background (with official API and apart from Audioplayers, GPS tracking apps and other specially desinged models for that). A diffrenet case is also an App running under the lock screen (it is possible, but it's not what you are asking for). When you navigate away from your App, then Suspending event is raised or (Deactivated in WP Silverlight) - note also that you have very limited time with those events to save the state of your App.
There are ways for working in background, apart from BackgroundAgents, starting from Windows Phone 8.1 (both Silverlight and Runtime) you can use BackgroundTasks. They can be triggered (for example TimeTrigger, MaintanceTrigger) depending on their Registration - in time intervals and/or upon special conditions.
Here is a vary good article, and you can also find some information at this article.
回答2:
It seems that you need a PeriodicTask
Periodic agents run for a small amount of time on a regular recurring interval. Typical scenarios for this type of task include uploading the device’s location and performing small amounts of data synchronization.
Source: Backgrounds agents for Windows Phone 8
来源:https://stackoverflow.com/questions/24235082/execute-a-windows-phone-8-1-application-after-deactivation