Windows Phone: multitasking and local database

20
Multitasking and Local Dababase in Windows Phone Mango Radu Vunvulea

Transcript of Windows Phone: multitasking and local database

Page 1: Windows Phone: multitasking and local database

Multitasking and Local Dababase in

Windows Phone Mango

Radu Vunvulea

Page 2: Windows Phone: multitasking and local database

Windows Phone MangoMultitasking

Page 3: Windows Phone: multitasking and local database

Multitasking

Resource Management

Built-in services 3rd-party services

Alarms & Reminders

File Transfers

Background Audio

Periodic Execution

Fast App Switching

Page 4: Windows Phone: multitasking and local database

Multitasking and Phone Health

Monitor resource usage

Align with system and user activity

Balance foreground and background

Processing on demand

New OS services

Page 5: Windows Phone: multitasking and local database

Application Lifecycle

Save state but do not discard it

Reload / refresh state only if needed

Application is resident in memory; system detaches resources and pauses threads

Tombstoned

DeactivatedDormant

RunningActivated

Page 6: Windows Phone: multitasking and local database

Deactivated

RunningActivated

Save state but do not discard it

Reload / refresh state only if needed

Application is resident in memory; system detaches resources and pauses threads

Tombstoned

Dormant

Application Lifecycle

Page 7: Windows Phone: multitasking and local database

Background transfer

20 MB 20 MB

100 MB

Unlimited

Page 8: Windows Phone: multitasking and local database

End-to-End Architecture

System Services

ISO StoreCloud

LogicUX

MyApp.dll

Application OS

Logic

MyAppAgent.dll

Single App

DeveloperMyApp Solution

MyApp Project

MyAppAgent Project

WMAppManifest

Page 9: Windows Phone: multitasking and local database

Demo

Page 10: Windows Phone: multitasking and local database

Background Agents

Ce ne este permis:• Base API• Update de tile• Toasts• Location• Networking• Storage

Ce nu ne este permis:• Librarii XNA• Audio• Senzori• Microfon• Camera• UI

Page 11: Windows Phone: multitasking and local database

Differences Between Agents

Periodic Agent• Runs every 30 minutes

• Any network connection

• Runs for 25 seconds

• Used for location, data sync,

etc.

Resource-Intensive Agent• Runs on external power

• Non-cell network

connection

• Runs for 10 mins, recurring

• Used for daily tasks, large

data syncs, etc.

Page 12: Windows Phone: multitasking and local database

Windows Phone MangoLocal Database

Page 13: Windows Phone: multitasking and local database

Where is database stored

Application

Data Context(Sistem.Data.Linq)

IsolatedStorage

LocalDatabase

LINQ to SQL Runtime

Page 14: Windows Phone: multitasking and local database

Good to know

• Isolated Storage is used to store database files

• LINQ to SQL is used as the ORM engine

• LINQ is used to query data

• Only System.Data.Linq assembly must be added to the project.

Page 15: Windows Phone: multitasking and local database

Database design

• Custom connection string format: "Data Source='isostore:/MyDir/DbName.sdf'"

• T-SQL queries are not supported

• The code-first approach to defining the database schema is preferred in this version of Windows Phone 7.1 Mango.

Data Source='isostore:/MyDir/DbName.sdf'

Page 16: Windows Phone: multitasking and local database

Limitations

• ADO.NET Objects are not supported• Skip() and Take() require an ordered list and

constants values• Only Microsoft SQL CE data types are

supported• BinaryFormatter is not supported by default

(hack: CustomType and implement ToString() and Parse() in your custom class)

• ExecuteCommand is not suported – NO T-SQL, NO DML statement, NO DDL

Page 17: Windows Phone: multitasking and local database

Process to follow to use SQL CE

Implement all database classes: tables, columns,

relations, datacontext, etc

Create a new database (.sdf) file in Isolated Storage(by

default the database is empty)

Populate the database stored in

the Isolated Storage with data

Page 18: Windows Phone: multitasking and local database

Code Sample

Page 19: Windows Phone: multitasking and local database

?Questions

Page 20: Windows Phone: multitasking and local database

Radu [email protected]

vunvulearadu.blogspot.com

Multumesc