c# - Run background service in android for data syncing -


i'm new xamarin platform. i'm developing application android platform using xamarin.forms. how can sync data server in background. want upload data internet connection available , @ time whatever user doing.

here sample service code have tried

[service] public class longrunningtaskservice : service {     public override ibinder onbind (intent intent)     {         return null;     }      public override startcommandresult onstartcommand (intent intent, startcommandflags flags, int startid)     {         // start task here         new task (() => {             // long running code             dowork();         }).start();          return startcommandresult.sticky;     }      public override void ondestroy ()     {         base.ondestroy ();     }      public void dowork ()     {         while (true)          {             //printing text checking if service continously running or not             log.write ("hello");             thread.sleep (5000);         }     } } 

now start service have wriiten following code on activity class

this.startservice (new intent (this, typeof(longrunningtaskservice))); 

so task writing sample text in file in each 5secs, problem if application closed user using recent activity button of mobile, task stopped , text writing in log file stopped.

i need keep running task on timely manner , internet connection gets available , there local data uploaded on server, should upload data , keep checking new files on local device.

thank you


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -