windows phone app running in the background - windows-phone-7

Is it possible to create an app the runs in the background? If so is there any samples out there for this?

In Windows Phone OS 7.1 you can actually use Background Agents now to perform tasks in the background.
from MSDN:
Scheduled Tasks and background agents allow an application to execute
code in the background, even when the application is not running in
the foreground. The different types of Scheduled Tasks are designed
for different types of background processing scenarios and therefore
have different behaviors and constraints.
You can use a PeriodicTask or ResourceIntensiveTasks. Read more about it in the MSDN article above.
And here's some sample code for you to integrate background agents into your existing app.
Sample Code: Background Agents in Mango

An application in the foreground can continue to run when the phone screen is locked(not background but...) by setting the PhoneApplicationService.ApplicationIdleDetectionMode property. By setting up your application to run when the phone screen is locked, a user is able to access the application quickly upon unlock. However, when your application runs under a locked screen, it could consume power outside of the user's control. For this reason, your application must minimize power usage when running under a locked screen

At the moment there is no way to create application that runs in background.

True multitasking for 3rd party Windows Phone 7 apps will come as an OS upgrade later this year. However, unless the app has to absolutely run in the background (like Pandora etc.), we as developers share some responsibility in making our apps feel at home with the rest of the OS.
Windows Phone OS offers app developers chances to save state of their applications to give the end users the feeling that it never stopped running; this is essentially the same as in other mobile platforms. As your app is being deactivated/closed, you have the option to "Tombstone" your state so that your users can come back to just where they left with BackStack navigation or future launches. Channel 9 had a nice set of demos & labs around tombstoning, found here.
Hope this helps!

Related

Location Service is not running in ios and android background for Xamarin

I am developing an app in Xamarin Forms which will show thing live position of the user on a map and all the users having the app can track other users movement.
Right now the app is working fine in android. But in the iOS foreground, android background it stops after some time. It is not at all running in ios background when I put the app in the background it stops showing the location and stops fully.
Please share some idea to keep the app live in background and foreground mode for the whole day.
Generally speaking, mobile OSs will stop your apps, when they are in the background for some time. How strict the OSs are depends on the OS and the version. iOS has "always" been very strict about it, Android has been a bit more loose in older versions, but is quite restrictive in newer versions. Anyway, getting the location in background is quite a common use case and OSs are providing you options to do it nevertheless, if you ask them politely.
iOS
As of iOS 11, there is a distinction between updating the location when in use and when in background. The user can choose which one to grant and you'll have to handle it appropriately.
According to this guide you'll have to add the NSLocationAlways key to your Info.plist to contimue getting the location when in background.
Android
From the Android developer guide
In an effort to reduce power consumption, Android 8.0 (API level 26) limits how frequently background apps can retrieve the user's current location. Apps can receive location updates only a few times each hour.
Anyway
The system distinguishes between foreground and background apps.
An app is considered to be in the foreground if any of the following is true:
It has a visible activity, whether the activity is started or paused.
It has a foreground service.
...
According to this, you can create a foreground service, see here more about it
For this reason, foreground services must show a status bar notification with a priority of PRIORITY_LOW or higher, which helps ensure that the user is aware of what your app is doing.
So if you are starting a foreground service that is shown in notification bar, you should be able to retrieve updates, even if your apps main Activity is not in foreground.

Is there a way to launch an app in background in windows phone 8.1....?

I am trying to launch an app(created myself, registered for a specific uri), from another app, using
Windows.System.Launcher.LaunchUriAsync(uri, options); an I was able to do it.
I want set the options such a way that my calling app remains on top. I read that it can be done on windows desktop by setting LauncherOptions.DesiredRemainingView
, which is not supported by Windows Phone. Is there any other way to achieve the same?
No, there is no way to do that on Windows Phone. There is only one active app at a time, and it is the one in the foreground.
There are background agents for things like VoIP and music, but that won't do what you want.

Location Tracking in Background

I am developing a windows phone app that uses users current location, I am making the app in 7 OS. My question is, Can I track the location in background, that is when the screen is locked?
I know this is a possibility in wp8 as it provides us with GeoLocator class, but can I achieve this in wp7? I am basically making a runtracker app hence I would like my app to track the location even when its in background, is it really feasible?
Your help is always appreciated!!
It is possible to keep the app running under lock screen, as it does, for example, Endomondo app.
Using Idle Detection, you can keep the app on, although screen is locked, and you can keep on tracking the location. Actually, it is not running in background, but in the foreground. Just the screen is locked. So, be careful not to drain user's battery.
You have to set the PhoneApplicationService.ApplicationIdleDetectionMode property to Disabled, for example in InitializePhoneApplication() method in App.xaml.cs:
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
Note that there are special certification requirements for this type of apps. Refer to section 6.3 (Apps running under a locked screen) of the following page:
Additional requirements for specific app types for Windows Phone
I got the same problem in one on my apps..
I don't think it' s feasible for wp7..
Bt if you want to do it with wp8 you can refer following link.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681691%28v=vs.105%29.aspx
And to know about background supported and unsupported API's http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202942%28v=vs.105%29.aspx/css
GeoCoordinateWatcher Class exists in WP7, but here is the documentation from MSDN -
This API, used for obtaining the geographic coordinates of the device,
is supported for use in background agents, but it uses a cached
location value instead of real-time data. The cached location value is
updated by the device every 15 minutes.
More Info : http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202962%28v=vs.105%29.aspx/css

GPS based application not running under lock screen in windows phone

I have developed a windows phone application and it works fine when it is open and running actively.
It tracks the user movements on the map and shows the position moves with push pins.
Now I want to ensure that the same application runs even the phone is locked when this app was open.
I have added the below code for it to work under lock screen. After this when I verified the app I realized it is not running when the application is locked.
Is there any other change I need to make to get this work under lock screen.Any help would be greatly appreciated.
private void initiliazesettings()
{
PhoneApplicationService.Current.UserIdleDetectionMode =
IdleDetectionMode.Disabled;
}
To have your app running under lock screen on Windows Phone 7.0/7.1/8.0, you need to set ApplicationIdleDetectionMode, not UserIdleDetectionMode. See details here.
Supossing you placed the method in the right place, that code only keeps the screen on, but doesn't make your app run in background when the lock screen is activated. Windows Phone 7 apps cannot run in background, they get tombstoned.
For Windows Phone 8 this is possible - see the sample here from MSDN.
However for Windows Phone 7/7.1 you can't do this.
You can prevent the screen from locking due to the user not interacting with it (as your code shows). However if you manually lock the screen the app will still be made dormant or tombstoned and your location code won't run.
Your only other option is to use a scheduled background task to read the location of the phone, but bear in mind that this is far from real time data (it is a cached location and you only run once every 30 minutes in the best case scenario).

about Task Manager on Windows Phone

I'm developing a windows phone app, suppose my app is running, user click start key, my app will bring to background, then next user long press back key, the task manager will be shown. My question is here: How can update the screenshots of my app when it was brought to background? I don't want expose anything of my app outside even in the task manager, could I do it? Thanks.
How can update the screenshots of my app when it was brought to background?
You cannot. And it's not a task manager, but a "fast app switch", allowing the user to easy swap between applications. The screenshot you see, will be the last screen of your application when it was in the foreground.
And your application will not be running in the background.
No - you cannot change the image shown in the app switching UI. This is built in OS functionality.

Resources