App lifecycle and solution structure in Xamarin.Forms

TamasMatraiTamasMatrai HUUniversity ✭✭

After some days of experiments I finds Xamarin.Forms really-really cool, I am getting to feel the 'taste' of it. Now I decided to start developing a more complex app. I have question about its structure.

In my app I need periodically make HTTP requests and parse their response. It must run during the whole time, when app is in active-visible state (not stopped, not paused, not in the background etc), it not depends the current visible view controller / activity.

I found Device.StartTimer that can be used in PCL to make my requests periodically, but I could not decide yet, where to hold a single instance of my DataFetcher class (it can not be static!) which's methods should be called periodically. Should I create a singleton class in my PCL? Where to hold it as a property? E.g. in IOS I could store it in AppDelegate (...), but I don't know if there is a cross-platform way for it.

And how do I know about the lifecycle of the app? Should I handle it in the .android and .ios projects, or is there some cross-platform way to do it?

Thank you very much!

Posts

  • MihaMarkicMihaMarkic SI ✭✭✭✭

    I'd go with a singleton. There is no app lifecycle support yet AFAIK, but you can proxy those from device specific layer (i.e. on Android just catch OnResume, OnPause and send them where you need them).

  • TamasMatraiTamasMatrai HUUniversity ✭✭

    @MihaMarkic Thanks. I started to do some experiments with singleton, and I also feel it a good solution.

Sign In or Register to comment.