Alexander Anikin's blog

My personal blog

Archive for the ‘C#’ Category

Monodroid: WebView input/textarea never get virtual keyboard focus

leave a comment »

Today I found a very strange issue.

This looks like here.

But we can reproduce this on 1-2 of our devices like Nexus, Xoom… (May depends on Android 4.1.x version)

So – WebView creating, opening html, but no one input/textarea get virtual keyboard focus.

I tried every solution for that link, and just only #35 helps me (big thanks to author):

For those who encountered this issue on Jelly Beans:
When you use one of the WebView constructors with more then 2 arguments applying the defStyle parameter, the default style will not be applied! For me the fix was to set the defStyle parameter to android.R.attr.webViewStyle.

e.g. to init a WebView with private browsing use

new WebView(this, null, android.R.attr.webViewStyle, true)

where this is a Context.

Hope to have saved somebody days of investigation (as in my case)..


But my project is on Monodroid. I couldn’t find  android.R.attr.webViewStyle value in Monodroid and just find it in SDK 

My constructor now  looks like:

const int WEVVIEWSTYLE = 16842885;

public MyWebView (Context context) : base(context, null, WEVVIEWSTYLE)

Awesome, but why?!



Written by Alex Anikin

April 11, 2013 at 10:00 am

Posted in C#, Monodroid

Memory Warning Received and PushViewController

leave a comment »

It was really  great investigation about why iOS application goes to black screen and craches sometimes.

Fisrst of all, I saw this: Received memory warning. Level 1

After that it goes to black screen. This is very interesting, application was working fine if no applications was started in background (I imagined – there are no free memory… but strange…). But, as I can see later, this is view was unloaded only. Several articles wrote – if view has no SuperView it will be unloaded when UIViewController receive memory warning. But this was obviously our fault. After huge  changes in UI we decided to use only one UIWebView. But some code was moved to new version, and  PushViewController invoke too. This is not clear for me now what exactly change this method, but it do something and view unloading after memory warning receive.  So we just remove this line and no black screen (means unloaded view) now.

Written by Alex Anikin

August 4, 2012 at 7:53 pm

Posted in C#, iOS, Mac, Monodevelop, Monotouch

Predictable memory disposing in Monotouch

leave a comment »

I have tasks:

– do huge memory block allocation in iOS (using Monotouch) application (like list with ~20Mb strings);

– clear list and have predictable memory disposing (using Garbage Collector, it should do this in time, or when we need more mem or etc).

This tasks was born from another big task. I should open huge txt files using QLPreviewController. But all I can see – memory was allocating and never disposing (but this story not about it, this leak Xamarin planning to fix it in 5.3.5 or 5.3.6 release – will wait ).

To check this allocations I used XCode -> Instruments -> Activity Monitor (btw very useful tool – highly recommended!)

My tests :

1. Alloc 20Mb -> check it in Activity Monitor (+20Mb)-> Dispose variable -> Wait and do something with app (alloc more, add, delete items) -> Check -> nothing changes – 20Mb still.

2. Alloc 10*20 Mb items-> Check – my app has almost the memory (if i will try to get more ~10-20Mb  – iOS will close my app) -> Dispose 5 items (~100Mb) -> Waiting (thinking about GC) + do something (thinking about GC again) -> Check  – nothing – ~200Mb

3. The same with 2, but start use GC.Collect (GC.MaxGeneration, GCCollectionMode.Forced); after disposing – Waiting (thinking about GC) + do something (thinking about GC again) -> Check  – nothing – ~200Mb

4. …

n. Wow! -> The same with 3, but after allocation I add GC. AddMemoryPressure (size); and after disposing GC. RemoveMemoryPressure (size); -> Activity monitor shows me that I have memory cleared and available for future allocations.

I can be wrong somewhere and please let me know my mistakes.

Written by Alex Anikin

July 10, 2012 at 9:46 pm

Posted in C#, iOS, Monotouch

Making a Request to WebService in Visual Studio from Specific IP address

leave a comment »

Hey all  –


1. I have a web-service refference in my project. I update it time to time. It’s OK.

2. I have several network adapters in my system.

The main thing – I need to call a WebMethod refferenced in my project from specific IP.


As you can see – VS generating class for Web Service Refference and it’s partial. So you can override  some very useful methods. In my case I should override GetWebRequest and change it’s properties. For changing EndPoint I should use ServicePoint.BindIPEndPointDelegate.


public IPEndPoint BindIpEndPointCallbackForIP(ServicePoint servicePoint, IPEndPoint remoteEndPoint, int retryCount)
return new IPEndPoint(_currentLocalIp, 0);

protected override WebRequest GetWebRequest(Uri uri)
HttpWebRequest request = (HttpWebRequest) base.GetWebRequest(uri);
request.Timeout = 10000;
if (_currentLocalIp != null)
request.ServicePoint.BindIPEndPointDelegate = new BindIPEndPoint(BindIpEndPointCallbackForIP);
return request;

I’m trying to make end-point (string in bold) with specific port (ex. 443 or 80), but it fails (why?). And in my case it doesn’t work with IPv6.

Written by Alex Anikin

February 13, 2012 at 2:50 pm

Posted in .Net, C#