Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

DidEnterBackground doesn't seem to be called?

$
0
0

Hi,

I've tried following the Xamarin backgrounding tutorial for background tasks and it doesn't seem to be running.

In the AppDelegate class I've overridden the DidEnterBackground method like so:

        // Background task can run for up to 10 mins after the app is hidden
        public override void DidEnterBackground (UIApplication application) {
            Console.WriteLine ("DidEnterBackground");
            int taskID = UIApplication.SharedApplication.BeginBackgroundTask (() => {});
            new Task (() => {
                var t = new Thread (() => {

                    // Perform Sync
                    Sync.All();
                    UIApplication.SharedApplication.EndBackgroundTask(taskID);

                }
                );
                t.Start ();
            }).Start ();
        }

Also I tried it first without the extra thread inside the background task but that didn't seem to work either.

Am I implementing this correctly?

The Sync.All method is attempting to send/receive data to a web service. Basically we are connecting the app to our cloud service but we need to do a full sync as/before the user exits.

Also how do I know if DidEnterBackground is running at all? I tried Console.Writeline and also a breakpoint for the debugger but neither do anything (which fits with my assumption that the entire method is not being called).

Much appreciated.

LR


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>