xamarin - CrossMedia.Camera backs to main page after take a photo -


i'm using plugin.crossmedia in xamarin forms, , sometimes, after camera takes photo, application turn main page, , worked lost in actual page, including image. occurs on android (5, , 6).

i'm doing this:

if (!crossmedia.current.iscameraavailable || !crossmedia.current.istakephotosupported) {     return; }  var photoname= "photo.png"; var sizeimg= plugin.media.abstractions.photosize.small; var mediaoptions = new plugin.media.abstractions.storecameramediaoptions {     savetoalbum = false,     allowcropping = true,     defaultcamera = plugin.media.abstractions.cameradevice.rear,     name = photoname,     photosize = sizeimg };  using (var file = await crossmedia.current.takephotoasync(mediaoptions)) {     if (file == null)         return;      var filepath = file.path;        ... move image  } 

when os needs memory perform app's request, in case using camera, having activity restarted common occurrence on lower end devices; limited memory, android one , new oreo-based android go devices.

xamarin.forms runs within single activity (typically template-created mainactivity) , application & page lifecycle events mapped within activities' lifecycle events.

xamarin.forms' termination:

note there no method application termination. under normal circumstances (ie. not crash) application termination happen fom onsleep state, without additional notifications code.

re: forms' lifecycle methods

some practices follow:

  • profile app's memory usage

  • ensure releasing resources no longer needed, images typically largest consumer of memory within app

  • request higher importance app when launching external app creating dummy service , request importancereason.serviceinuse android os.

    note: not prevent os terminating process,       provides hint os... 
  • when opening external apps such camera, chrome via custom tabs (xamarin.auth), etc... , user expecting return same state, ensure have persisted app's state can restore it.

  • read on android's activity lifecycle when activity's oncreate called bundle know app restarting , can retrieve , pass app specific state information forms' application subclass determine forms navigation stack rebuild , page open, i.e.:

    if (bundle null)     loadapplication(new app()); else {     var restoreappstate = getpriorappstate();     loadapplication(new app(restoreappstate.restore2page)); } 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -