17

Click here to load reader

Windows Phone and mobile application development

Embed Size (px)

DESCRIPTION

Windows Phone 7 platform overview. Mobile application development for Windows Phone platform basics. Multitasking and services with Phone 7.

Citation preview

Page 1: Windows Phone and mobile application development

WINDOWS PHONE 7MULTITASKING & BACKGROUND

TASKS

Roman Ivasyshyn Softjourn Inc.

Page 2: Windows Phone and mobile application development

Topics

Platform overview Multi-Tasking with background agents Windows Phone Task Manager Background Notifications File Transfer Tasks, Music Playback Tasks

Page 3: Windows Phone and mobile application development

Platform overview

Intelligent OS and well designed API Powerful instrumentation and language Up to date mobile OS WP7 Marketplace now available for Ukraine Multitasking Push notifications Implementation of social network API

Page 4: Windows Phone and mobile application development

Foreground tasks

Normally a windows phone application runs in the foreground

At any given time one application is running in the foreground

This is to ensure the best performance and battery life for the phone user

Page 5: Windows Phone and mobile application development

Background agents Windows Phone application can start a

background agent. It is PeriodicTask, ResourceIntensiveTask or both at

same time There is only one agent allowed per application

The agent can run only when the main application is not in the foreground

Agent is not equivalent to foreground application running in the background

It's limited in what it can do and the access it has the processor and other phone facilities

Page 6: Windows Phone and mobile application development

Background Agent restriction

The number of Agents allowed to be active at one time is restricted by the Windows Phone system

If the right conditions do not arise, Agent will not be started

The background agents only run in situations where the system feels able to give them access to the processor

If the phone goes into “Power Saver” mode it may stop running background agents completely

User can also manage the agents running on their phone and may chose to disable them

Don't put any critical logic into yours app background agent

Page 7: Windows Phone and mobile application development

Agent and Tasks A Task is the container that is managed by the

operation system and runs at the appointed time

It runs an Agent which does the work The agent code is called as a method in a class The class is created as part of a Scheduled Task Agent

Project

There are two kinds of Task Periodic tasks that are runs through a certain period of

time Resource intensive tasks that run where the phone in a

position to let them

Page 8: Windows Phone and mobile application development

Periodic task agent

A periodic task agent runs every Typically every 30 minutes or more, depends on phone

loading

It is intended to perform a task that should be performed regularly and complete quickly

The agent is allowed to run for 25 seconds or less The phone sets a limit on the maximum number of active

at any time

Good for location tracking, polling background services etc.

Page 9: Windows Phone and mobile application development

Resource intensive agents Resource intensive agents run where the phone

is in a position where it can usefully perform some data processing

Where the phone is powered by the main Where the phone is connected to WiFi Where the phone is not being used (locked screen

displayed)

A “Resource Intensive”

agent can run for up to

10 minutes

Page 10: Windows Phone and mobile application development

Dual purpose agent It is possible for application to perform both

periodic and resource intensive tasks in the same time

This can be achieved using a single background agent class, run from both kind of task

The agent will run periodically and when phone is in a position to allow resource intensive work

When the agent starts it can determine the context in which it is running and then behave appropriate

Page 11: Windows Phone and mobile application development

Background and Foreground communication For Periodic and Resource-intensive Agents:

LINQ 2 SQL, file in isolated storage that is guarded with a Mutex.

Avoid IsolatedStorageSettings

For Audio Agents: Store custom data in the Tag property of the AudioTrack class.

Use methods NotifyConplete or Abort to set state flag

Toast and Tile notification

Page 12: Windows Phone and mobile application development

Windows Phone Task Manager

Page 13: Windows Phone and mobile application development

File transfer tasks It is also possible to create a background task

to transfer files to and from your application's isolate storage

The transfers may perform where the application is not running

File can be downloaded from HTTP or HTTPS hosts

The system maintains a queue of active transfers and services

Application can query the state of active transfer

Page 14: Windows Phone and mobile application development

Background transfer policies

There are a set of policies that control transfer behavior

Maximum Upload file size: 5Mb Maximum Download file size over cellular: 20Mb Maximum Downloads file over WiFi: 100Mb

These can be modified by setting the value of TransferPreferences on the particular transfer

Page 15: Windows Phone and mobile application development

Audio Playback Agent

The audio can be streamed There are no ability to play music from library

(only from application's isolate storage)

Page 16: Windows Phone and mobile application development

Conclusion

Use background tasks to perform particular job DO NOT put any critical logic into yours app

background agent There are a set of default backgrounds agent

designed for common tasks

Page 17: Windows Phone and mobile application development

Questions