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 555769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:50:57+00:00 2026-05-13T11:50:57+00:00

How can I store/access global variables within a monotouch application? I am retrieving the

  • 0

How can I store/access global variables within a monotouch application? I am retrieving the GPS Location (using Monotouch.CoreLocation.CLLocationManager) during the FinishedLaunching method of the AppDelegate. How do I then access that information from a property on that appdelegate (from a view, for example)? Or is there another preferred method for global data?

UPDATE:
I just want to grab the location once, at startup, then have access to that location from all my views. Here’s my AppDelegate – I’d like to access the locationManager field from a view. I can certainly add a property to do so, but I guess my question is “How do I access that property from a view (or can I even, considering it’s a delegate)”?

// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
    private CLLocationManager locationManager = new CLLocationManager();

    // This method is invoked when the application has loaded its UI and its ready to run
    public override bool FinishedLaunching (UIApplication app, NSDictionary options)
    {   
        locationManager.Delegate = new GpsLocationManagerDelegate();
        locationManager.StartUpdatingLocation();

        window.AddSubview (navController.View);
        window.MakeKeyAndVisible ();        
        return true;
    }

    // This method is required in iPhoneOS 3.0
    public override void OnActivated (UIApplication application)
    {
    }
}
  • 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-05-13T11:50:57+00:00Added an answer on May 13, 2026 at 11:50 am

    Generally, most people will tell you to avoid global variables and instead pass what you need into the delegate. (I would agree with that sentiment).

    However, you can use a singleton class, a service locator, or a static class with static fields/properties to get global variable-like behavior in C# (or any other Dotnet/Mono compatible language).

    In your case, I presume you wrote the class GpsLocationManagerDelegate yourself. If so, you can change the constructor to take parameters for the necessary information (the view, a reference to the app delegate, and/or a reference to the location manager) and store it in your GpsLocationManagerDelegate instance. If you didn’t write GpsLocationManagerDelegate yourself and it’s not declared sealed, subclass it and create an appropriate constructor.

    This example seems close to what you’re after: http://www.conceptdevelopment.net/iPhone/MapKit01/Main.cs.htm

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

Sidebar

Related Questions

I know you can access the Contact Store from the SDk, but is it
Say you have a bunch of files. Say you can store meta data to
As you know, in ASP.NET, you can store session data in one of following
Can I store a database connection in the Session object?
How can I store a hash table with separate chaining in a file on
Any gotchas I should be aware of? Can I store it in a text
Can i run download applications from Apple Store on iPhone simulator?
Can someone suggest a good module in perl which can be used to store
Can anybody help me out to know the possible reasons for which Apple store
How can I remove those annoying Mac OS X .DS_Store files from a Git

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.