-1

I'm running into the questions if it's a problem to mark FormsAppCompatActivity.OnCreate(Bundle bundle) as async? I have to fetch user-specific data from an AWS DynamoDB, and I need to retrieve the user from the Akavache cache before in order to query with the userId. Of course, I could also save the userId to the local settings or serialize the whole user object to be able to retrieve it synchronously.

I also don't expect performance issues during startup because the cache uses SQLite definitely exists. The only problem is that either I await Akavache's GetObject<T>(string key) and therefore, mark everything down to OnCreate as async, or I subscribe to the returned Observable and the following methods will try to query the user data without a valid userId, because the Observable hasn't returned yet.

zirkelc
  • 1,451
  • 1
  • 23
  • 49

1 Answers1

1

Since you're using XF for development, the code LoadApplication(new App()); in OnCreate of MainActivity will hook the lifecycle event to App's lifecycle event in PCL.

You didn't post any code, I guess that you place your code for data fetch after LoadApplication(new App());, then as you said it didn't return yet, otherwise the behavior should be different.

I suggest you to call your task in the OnStart() of App in PCL and together use DependencyService to call into your async task for fetching data from PCL.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • I implemented different start methods in `App` which I call from `OnCreate` based on the Intent I'm receiving. Because I always have to fetch the user as part of the login process, I needed to call the async method from all start methods and therefore, mark them async as well as `OnCreate`. I haven't thought about just using the `OnStart` method instead and mark it as async. I'll try that - thanks! :) – zirkelc Aug 08 '17 at 07:03