8

While testing an Android application that contains a couple of Entry textboxes and a map with geolocation enabled, I found that if I clicked the back button on Android while the on-screen keyboard was up (that is, while inserting text on one of the Entries), the app would crash and I'd get the following exception logged on the debug output:

09-09 00:10:38.187 I/MonoDroid(14174): UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Maps.Android.MapRenderer from native handle b250001d ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Maps.Android.MapRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.

Whole stack trace here: http://pastebin.com/hDAS4JLV

Some things to keep in mind:

1 - The keyboard types used on those textboxes are Text and Telephone.

2 - Contrary to what the stack trace tells, I am not using the camera at all on the application.

3 - The MapRenderer does not come with such a constructor on Xamarin Forms. Mind you, I'm using Xamarin.Forms 1.2.3 (the -Pre version).

4 - I tried adding a Custom Map Renderer with a dummy constructor that accepted the required params according to the exception, to no avail.

5 - This does not happen on any other (tested) situation, only when the on-screen keyboard is displayed.

6 - This does not happen in the iOS version.

7 - The same steps were tested on several devices (Galaxy Nexus, Galaxy S5, Alcatel One Touch) with the same result.

Priyansh
  • 1,163
  • 11
  • 28
EfrainReyes
  • 1,005
  • 2
  • 21
  • 55
  • 1
    Google Maps uses the Camera metaphor to describe what you are looking at on the map. Nothing to do with the actual hardware camera on the phone. – Cheesebaron Sep 10 '14 at 16:01
  • can you supply your full solution project? I'd also suggest updating to the latest stable releases and re-test. My contact details are on my Profile. – Pete Sep 11 '14 at 21:09
  • No can do, sorry. I'll attempt the stable release to check if it works. – EfrainReyes Sep 12 '14 at 19:34
  • 1
    if that doesn't work, try creating a small specific project that demonstrates the issue as this will be helpful to others trying to help. We have no idea if the issue is related to the way your implementing things or not at present, so its very hard to help at the moment. – Pete Sep 12 '14 at 22:16
  • Are you using MapView? If so your activity or fragment must call the all lifecycle methods (onPause, onDestroy, etc.) on the MapView. See the overview section of the class documentation for details http://developer.android.com/reference/com/google/android/gms/maps/MapView.html – Dave C Sep 18 '14 at 16:17
  • @EfrainReyes , did you get the solution to resolve this `bug`, I am facing the same problem while Tapping the `detailed` page more than once at a same time. – Jamal Jan 16 '17 at 11:05
  • @Jamal the error stopped showing up on the app I was working on at the time after an update. Wouldn't know if the error has resurfaced since I left the company that owns the app not long after I posted this question. – EfrainReyes Jan 16 '17 at 11:14
  • 1
    Thanks @EfrainReyes for your comment. – Jamal Jan 16 '17 at 12:01

1 Answers1

4

I encountered this problem multiples times in my project. What's happening in summary is that :

The hidden page can be released while our app is running by Android to save memory. Thus, when you go back to that page Android needs to recreate it.

When that happens Mono will create an instance of the appropriate type via the (IntPtr, JniHandleOwnership) constructor and later it will call the page constructor.

So the problem is that you need to implement the "(IntPtr, JniHandleOwnership) constructor" so that Mono can create the instance when needed. It usually looks like this :

public YourClassName(IntPtr javaReference, JniHandleOwnership jniHandleOwnership) 
    : base(javaReference, jniHandleOwnership) { }

John Pryor, the current lead of Xamarin Android has a pretty detailed answer about it which explains the behavior.

I actually already highlighted the important part of his explanation in this post.

Community
  • 1
  • 1
ForceMagic
  • 6,230
  • 12
  • 66
  • 88