On Apr 3, 2013, at 1:06 AM, Stephan Steiner <[email protected]> wrote:
> Why do you create your own Application on your code?

To ensure that ServicePointManager.ServerCertificateValidationCallback is only 
set once per process. Otherwise it'll be appended to every time that Activity 
launches; launch the Activity 5 times, and you'll have 5 callbacks hooked up to 
that property, which is crazy. It then gets crazier because your original 
validatedCertificate() method is an instance method, which means every time the 
Activity.OnCreate() executes and you hookup to the 
ServicePointManager.ServerCertificateValidationCallback property, you "leak" 
the Activity as it won't be collectable, ever.

For example:

1. Create the Default template app.
2. Annotate the OnCreate() method to Console.WriteLine("Launched; pid={0}", 
System.Diagnostics.Process.GetCurrentProcess().Id)
3. Build, deply
4. On device, Run the app. The "Launched" message is printed with current pid.
5. Click the Back button
6. Run the app again.

Two things should be noticeable with (6):

1. The app launches faster.
2. The Launched message printed in (6) has the same pid as the one in (4).

The reason it launches faster is because the process is reused. This in turn 
means that your Activity.OnCreate() method can be invoked multiple times for 
the same process, so if you're manipulating global state you need to be Very 
Careful that you're not screwing things up. ;-)

> Shouldn't registering the certificate validation callback registration take 
> from anywhere and remain until the app closes?

Yes, but you also need to worry about multiple registration.

 - Jon

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to