Execute a Windows Phone 8.1 Application after deactivation
Asked Answered
O

2

1

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?

Offbeat answered 15/6, 2014 at 23:41 Comment(1)
I'm not a Windows Phone expert, but this seems like a reasonable question to me. It might be helpful (to the OP and others) if someone could elaborate why it is being downvoted.Goddard
S
2

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.

Saporific answered 16/6, 2014 at 5:2 Comment(4)
Thank you Romasz for your answer. About Background Tasks, I've found that I can run tasks as frequently as every 15 minutes. As I explain to George I need to update device's location more frequently. In your knowledge, are there any ways to do it?Offbeat
@top_broker In Windows Phone build-in timer works with 30 minute interval (15 min is on Windows). So this way you won't go below that time. AFAIK there is no way to run task faster, but - there are some types of apps which are allowed to run in background continously - AudioAgent, Location Tracking apps. So if you want to update device's location - check MSDNSaporific
I need to continuosly track device's position and send this data to a server. Is this possible, using geolocator? The method geolocator_StatusChanged() can run even if the App is deactivated or can be executed as a background task? if yes, how? (this is what I really need to know :) )Offbeat
@top_broker I've tried that yet. Under WP8.0 when the App tracked location actively then the App was allowed to run in the background up to 4 hours (with some other limits). But I'm not sure how this works now in WP8.1 - you will have to check it. Also note that there were some API restriction while running in background.Saporific
S
3

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

Slr answered 16/6, 2014 at 0:12 Comment(4)
Thank you George for your answer. I've read the article and PeriodicTask seems to be what I need, but there are strong limits. A PeriodicTask can execute no more than 1 time per 10 minutes. In my app, I need background agents to update the device's location but I think it is useful to do it more frequently. Is it possible to execute background code more frequently?Offbeat
Are you sure about that? As you can see in this example, you can run the agent every minute. (At least in debug mode)Slr
ScheduledActionService.LaunchForTest() allows to run agent every minute only (unfortunately) in debug mode but I need this feature also in the final release.Offbeat
Can u send me your source to the 10 minute limitation?Slr
S
2

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.

Saporific answered 16/6, 2014 at 5:2 Comment(4)
Thank you Romasz for your answer. About Background Tasks, I've found that I can run tasks as frequently as every 15 minutes. As I explain to George I need to update device's location more frequently. In your knowledge, are there any ways to do it?Offbeat
@top_broker In Windows Phone build-in timer works with 30 minute interval (15 min is on Windows). So this way you won't go below that time. AFAIK there is no way to run task faster, but - there are some types of apps which are allowed to run in background continously - AudioAgent, Location Tracking apps. So if you want to update device's location - check MSDNSaporific
I need to continuosly track device's position and send this data to a server. Is this possible, using geolocator? The method geolocator_StatusChanged() can run even if the App is deactivated or can be executed as a background task? if yes, how? (this is what I really need to know :) )Offbeat
@top_broker I've tried that yet. Under WP8.0 when the App tracked location actively then the App was allowed to run in the background up to 4 hours (with some other limits). But I'm not sure how this works now in WP8.1 - you will have to check it. Also note that there were some API restriction while running in background.Saporific

© 2022 - 2024 — McMap. All rights reserved.