windows phone 7 - Update live tile when exiting app - any restrictions/best practices -


i have app update live tile when user leaves app. first question if bad idea? if user starts app 20 times per day bad idea or in way affect background service?

second question if there limit how long or resource intensive might be. guess put code in onnavigatedfrom, os kill app if updating of live tile takes long? need create image, save isolated storage, read image , update tile.

really looking forward thoughts on this.

edit 1: reason me asking if above works fine. if exit app when starts black tile instead of tile background image. impression code doesn't finish. how can avoid that?

edit 2: since i'm creating live tile dynamically think problem loading of background image. load background image , add text it. when tile goes black can still see text there must loading of background image used background tile.

edit 3:here complete code creation of image used background image. tried simplify little reduce code.

grid grid = new grid();  stackpanel sp = new stackpanel(); sp.height = 173; sp.width = 173;  sp.background = (solidcolorbrush)application.current.resources["phoneaccentbrush"]; strbackbackground = "";  streamresourceinfo info;  sp.background = (solidcolorbrush)application.current.resources["phoneaccentbrush"]; strbackbackground = ""; info = application.getresourcestream(new uri("/myapp;component/images/icons/livetile/metro-" + strsymbol + ".png", urikind.relative));  // create source bitmap image control (image assumed alread 173x173) writeablebitmap wbmp3 = new writeablebitmap(1, 1); try {     wbmp3.setsource(info.stream); } catch { }  image img3 = new image(); img3.source = wbmp3; // add image grid img3.width = 173; img3.height = 173; img3.margin = new thickness { left = 0, bottom = 0, right = 0, top = 0 };  textblock txttemperature = new textblock(); textblock txttemperaturering = new textblock();  txttemperature.foreground = new solidcolorbrush(colors.white); txttemperature.text = strtemp; txttemperature.textalignment = textalignment.right; txttemperaturering.style = (style)application.current.resources["phonetexttitle3style"]; txttemperaturering.fontfamily = new fontfamily("segoe wp light"); txttemperaturering.fontsize = 40; txttemperaturering.foreground = new solidcolorbrush(colors.white); txttemperaturering.text = "°"; txttemperaturering.textalignment = textalignment.right;  txttemperature.fontfamily = new fontfamily("segoe wp"); txttemperature.fontsize = 40; txttemperature.margin = new thickness { left = 0, bottom = 0, right = 0, top = -55 }; txttemperature.height = 80; txttemperature.width = 135; txttemperaturering.margin = new thickness { left = 130, bottom = 0, right = 0, top = -112 }; txttemperaturering.height = 50; txttemperaturering.width = 29;  sp.children.add(img3); sp.children.add(txttemperature); sp.children.add(txttemperaturering);  //call measure, arrange , updatelayout prepare rendering sp.measure(new size(173, 173)); sp.arrange(new rect(0, 0, 173, 173)); sp.updatelayout(); grid.children.add(sp);  writeablebitmap wbmp = new writeablebitmap(173, 173); wbmp.render(grid, null); wbmp.invalidate();  //write image isolated storage string sisostorepath = @"\shared\shellcontent\tile.png"; using (isolatedstoragefile appstorage = isolatedstoragefile.getuserstoreforapplication()) {     //ensure directory exists     string sdirectory = system.io.path.getdirectoryname(sisostorepath);     if (!appstorage.directoryexists(sdirectory))     {         appstorage.createdirectory(sdirectory);     }      using (isolatedstoragefilestream stream = new isolatedstoragefilestream(sisostorepath, system.io.filemode.create, appstorage))     {         wbmp.savejpeg(stream, 173, 173, 0, 100);     } }   /// if application uses both periodictask , resourceintensivetask if (task periodictask) {      shelltile tiletofind = shelltile.activetiles.first();       if (tiletofind != null)     {         standardtiledata newtiledata = new standardtiledata         {             backgroundimage = new uri("isostore:shared/shellcontent/tile.png", urikind.absolute),             title = strtitle,             count = null,             backtitle = (string)settings["selectedcityname"],             backbackgroundimage = new uri(strbackbackground, urikind.relative),             backcontent = strwind + environment.newline + strprecipitation         };          tiletofind.update(newtiledata);     } } 

there way avoid problems.

user closing app using "back" button, right? can take adventage of this.

just add method event, has executed completly before app closed. in mainpage() method type:

this.backkeypress += new eventhandler<system.componentmodel.canceleventargs>((sender, e) => {     blablablablabla - code; }); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -