Forum Xamarin.Android

Did anyone has implemented ILocationListener in Android without using event/delegates?

MikeDennisMikeDennis USMember ✭✭
edited March 2016 in Xamarin.Android

Application Crashes whenever this line of code executes:

this - > is always null... is it because of not running in the activity?

locMgr.RequestLocationUpdates(LocationManager.GpsProvider,10,10,this);

I have added the ILocationListener interface to the class in the native android:
`
var context = Xamarin.Forms.Forms.Context;
var locMgr = LocationManager.FromContext(context);
public void Dispose()
{
throw new NotImplementedException();
}

        public IntPtr Handle { get; }
        public void OnLocationChanged(Location location)
        {
            double lat=location.Latitude;
            double longit = location.Longitude;
        }

        public void OnProviderDisabled(string provider)
        {

        }

        public void OnProviderEnabled(string provider)
        {

        }

        public void OnStatusChanged(string provider, Availability status, Bundle extras)
        {

        }`

Error:
22:12:17.052 I/MonoDroid(15048): UNHANDLED EXCEPTION:
03-19 22:12:17.195 I/MonoDroid(15048): Java.Lang.IllegalArgumentException: invalid listener: null
03-19 22:12:17.195 I/MonoDroid(15048): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
03-19 22:12:17.195 I/MonoDroid(15048): at Android.Runtime.JNIEnv.CallVoidMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue* parms) [0x00063] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:571
03-19 22:12:17.195 I/MonoDroid(15048): at Android.Locations.LocationManager.RequestLocationUpdates (System.String provider, Int64 minTime, Single minDistance, ILocationListener listener) [0x0009f] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Locations.LocationManager.cs:950

03-19 22:12:17.195 I/MonoDroid(15048): --- End of stack trace from previous location where exception was thrown ---
03-19 22:12:17.195 I/MonoDroid(15048): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
03-19 22:12:17.195 I/MonoDroid(15048): at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:994
03-19 22:12:17.195 I/MonoDroid(15048): at Android.App.SyncContext+c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
03-19 22:12:17.195 I/MonoDroid(15048): at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
03-19 22:12:17.195 I/MonoDroid(15048): at Java.Lang.IRunnableInvoker.n_Run (IntPtr jnienv, IntPtr native__this) [0x00009] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Java.Lang.IRunnable.cs:71
03-19 22:12:17.195 I/MonoDroid(15048): at (wrapper dynamic-method) System.Object:3538a441-6bb8-4d97-8a8c-3120d478cd5b (intptr,intptr)
03-19 22:12:17.195 I/MonoDroid(15048): --- End of managed exception stack trace ---
03-19 22:12:17.195 I/MonoDroid(15048): java.lang.IllegalArgumentException: invalid listener: null
03-19 22:12:17.195 I/MonoDroid(15048): at android.location.LocationManager.checkListener(LocationManager.java:1693)
03-19 22:12:17.195 I/MonoDroid(15048): at android.location.LocationManager.requestLocationUpdates(LocationManager.java:455)
03-19 22:12:17.195 I/MonoDroid(15048): at mono.android.content.DialogInterface_OnClickListenerImplementor.n_onClick(Native Method)
03-19 22:12:17.195 I/MonoDroid(15048): at mono.android.content.DialogInterface_OnClickListenerImplementor.onClick(DialogInterface_OnClickListenerImplementor.java:29)
03-19 22:12:17.195 I/MonoDroid(15048): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:160)
03-19 22:12:17.195 I/MonoDroid(15048): at android.os.Handler.dispatchMessage(Handler.java:102)
03-19 22:12:17.196 I/MonoDroid(15048): at android.os.Looper.loop(Looper.java:135)
03-19 22:12:17.196 I/MonoDroid(15048): at android.app.ActivityThread.main(ActivityThread.java:5238)
03-19 22:12:17.196 I/MonoDroid(15048): at java.lang.reflect.Method.invoke(Native Method)
03-19 22:12:17.196 I/MonoDroid(15048): at java.lang.reflect.Method.invoke(Method.java:372)
03-19 22:12:17.196 I/MonoDroid(15048): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
03-19 22:12:17.197 I/MonoDroid(15048): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)
An unhandled exception occured.

Note: I don't want to use any plugins for location, as I need to use the android cache for locations

Answers

Sign In or Register to comment.