Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:23:24+00:00 2026-06-02T18:23:24+00:00

I am using the MvvmCross framework for cross device development. When I test my

  • 0

I am using the MvvmCross framework for cross device development. When I test my app in the Android emulator (I can’t test it on a physical device yet) I get an Java.Lang.IllegalArgumentException exception when calling RequestLocationUpdates on the LocationManager. Also, I don’t know whether it is relevant, but when I hover the mouse over the statement I get told that RequestLocationUpdates is an “Unknown Method”. This happens whether the exception has occurred or not.

It seems to only happen the second time I call it in my application but the code that clears it down between uses looks like it should work

    protected override void PlatformSpecificStart(MvxGeoLocationOptions options)
    {
        if (_locationManager != null)
            throw new MvxException("You cannot start the MvxLocation service more than once");

        _locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
        var criteria = new Criteria() { Accuracy = options.EnableHighAccuracy ? Accuracy.Fine : Accuracy.Coarse };
        var bestProvider = _locationManager.GetBestProvider(criteria, true);

        _locationManager.RequestLocationUpdates(bestProvider, 5000, 2, this);
    }

    protected override void PlatformSpecificStop()
    {
        EnsureStopped();
    }

    private void EnsureStopped()
    {
        if (_locationManager != null)
        {
            _locationManager.RemoveUpdates(this);
            _locationManager = null;
        }
    }

The class this is in inherits from Java.Lang.Object and I have verified that the PlatformSpecificStart and Stop and called at the appropriate times (i.e. the Stop is definitely called before the second Start). Can anyone tell me what is going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:23:25+00:00Added an answer on June 2, 2026 at 6:23 pm

    I’ve added a lesson in the tutorial that shows the IMvxGeoLocationWatcher interface being used.

    See the sample in https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.Core/ViewModels/Lessons/LocationViewModel.cs with code like:

        private void DoStartStop()
        {
            if (!IsStarted)
            {
                _watcher.Start(new MvxGeoLocationOptions() { EnableHighAccuracy = true }, OnNewLocation, OnError);
            }
            else
            {
                _watcher.Stop();
            }
    
            IsStarted = !IsStarted;
        }
    
        private void OnError(MvxLocationError error)
        {
            // TODO - shuold handle the error better than this really!
            LastError = error.Code.ToString();
        }
    
        private void OnNewLocation(MvxGeoLocation location)
        {
            if (location != null && location.Coordinates != null)
            {
                Lat = location.Coordinates.Latitude;
                Lng = location.Coordinates.Longitude;
            }
        }
    

    This seems to work OK on:

    • WP7 – https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.WindowsPhone/Views/Lessons/LocationView.xaml
    • Droid – https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.Droid/Views/Lessons/LocationView.cs
    • Touch – https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20Tutorial/Tutorial/Tutorial.UI.Touch/VIews/Lessons/LocationView.cs

    I haven’t yet written the code for WinRT…


    One thing that might be causing your errors is if you try to Dispose() the IMvxGeoLocationWatcher instance – doing this might lead to unpredicatable results.

    When dealing with GPS on WM6, iPhone, Bada, WP7 and Android for RunSat/Navmi (http://www.navmi.com) I’ve frequently encountered issues where the native platforms can be quite ‘unstable’/’unpredictable’ when the app starts/stops multiple location listeners – and I think this did influence the way I designed the IMvxGeoLocationWatcher functionality. In general, if your app uses IMvxGeoLocationWatcher then I think it’s best to wrap the access to the location in some kind of singleton accessed through an interface – doing this will allow you to have much easier control on the location functionality, rather than having multiple clients all individually trying to start/stop the location managers.


    If you find the functionality of IMvxGeoLocationWatcher isn’t what you are looking for, then by all means create your own interface and your own platform dependent implementations – they can be easily injected within each native Setup class.

    For example, one thing you might like to try is an interface using the Mono mobile extensions which are available for Location (as well as for Contacts and for some a growing number of other features too)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the MvvmCross framework to build a cross platform (iOS, Android, WP7)
I've created an app using MVVMCross, the IOS and Android versions are working but
We're developing a cross platform application for iOS, Android and WP7 by using MVVMCross
I have a view in a MonoTouch app using MvvmCross framework that I would
Using the HTML5 File API I can get the Binary String representation of a
Using Android TelephonyManager an application can obtain the state of data activity over the
Using the current request I can get the URL hostname with: HttpContext.Current.Request.Url.Host But -
Using Java, how can I extract all the links from a given web page?
Using Nunit, I want to be able to write a test fixture that will
Using PHP, I can convert MySQL data or static table data to csv, Excel,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.