Bug 27983 - [WatchKit] Awake and WillActivate are called after the initial interface controller's content is displayed
Summary: [WatchKit] Awake and WillActivate are called after the initial interface cont...
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.8.0
Hardware: Macintosh Mac OS
: Normal major
Target Milestone: 8.8 iOS8.2/WatchKit
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-03-12 15:13 UTC by Mike Bluestein
Modified: 2015-03-17 07:04 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
test case (25.97 KB, application/zip)
2015-03-12 15:13 UTC, Mike Bluestein
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Mike Bluestein 2015-03-12 15:13:53 UTC
Created attachment 10311 [details]
test case

The lifecycle methods Awake and WillActivate are being called after the content of the first interface controller in an app is displayed on the simulator. This leads to controls that can be interacted with by the user before and controller is fully initialized. Apple says that the UI should not be displayed until after these methods have been called. See the thread I started in the Apple forums:

https://devforums.apple.com/thread/264876?tstart=0

I included a trivial test case where the UI has only a button. You can see the UI displayed before the methods are called in the following screencast:

http://screencast.com/t/EAlnCEPc

The above was run on a fresh simulator (meaning I reset the content of the sim prior to running the app)

Also, here's another screencast of the same app where I can tap on the button and it's code runs before WillActivate:

http://screencast.com/t/aORWXqYUJikz

Let me know if you need any other info.
Comment 1 Mike Bluestein 2015-03-12 20:00:28 UTC
Curiously, I tried the test case again just to see if I can repro this every time, which I could, but in one case I got the iOS simulator to deadlock. 

As you see in this screencast (I've been known to like screencasts ;) both the watch sim and the iPhone are deadlocked (can't click the watch app button and can't do anything on the iPhone sim):

http://screencast.com/t/yosS0yBPs
Comment 2 Rolf Bjarne Kvinge [MSFT] 2015-03-13 04:32:10 UTC
This seems strange, because the UI in the watch simulator is one process (the watch app), and the code you're debugging is another process (the watch extension).

I'm not sure how Apple has synchronized the two, but it doesn't seem logical that the watch will hang until it has contacted the phone. Yet the deadlocked watch/sim seems to indicate that there is some synchronization going on.
Comment 3 Sebastien Pouliot 2015-03-16 10:24:50 UTC
@olf where you able to duplicate ?

IIRC that kind of situation can come up (outside of watchkit) if the .ctor calls some methods/properties that will trigger the rest of the initialization (part of why calling virtual methods from a .ctor is a bad idea ;-).
Comment 4 Mike Bluestein 2015-03-16 10:45:32 UTC
Hi Sebastien,

Empty constructor in this case (just what's added by the XS template):

		public InterfaceController (IntPtr handle) : base (handle)
		{
		}
Comment 5 Rolf Bjarne Kvinge [MSFT] 2015-03-16 14:47:58 UTC
I can reproduce this, but if I set the button's Identity/Name to something in the designer I can't reproduce anymore, which means this is something iOS does and not a problem with Xamarin.iOS.
Comment 6 Mike Bluestein 2015-03-16 21:44:15 UTC
Weird, so basically creating an outlet to the button made the issue go away?
Comment 7 Rolf Bjarne Kvinge [MSFT] 2015-03-17 07:04:56 UTC
@Mike, my guess is that without the outlet iOS for some reason decides to display a static UI at first, then loads the extension and your code.