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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:19:58+00:00 2026-05-27T20:19:58+00:00

Right now I am trying to design an Android app where a critical feature

  • 0

Right now I am trying to design an Android app where a critical feature is the ability to click on an area and set a flag there.
To teach myself how the Google Maps API work, I used the tutorial in the dev guide: http://developer.android.com/resources/tutorials/views/hello-mapview.html

At each step of the way, I tried to understand exactly what was going on. And for the most part, I got it. The one thing I don’t understand are the references to Context. Specifically, in the HelloItemizedOverlay class in that tutorial, there is the line

Context mContext;

and later on there are two constructors, one of which takes a Context object as an argument and the other of which does not.

public HelloItemizedOverlay(Drawable defaultMarker){
        super(boundCenterBottom(defaultMarker));
}

public HelloItemizedOverlay(Drawable defaultMarker, Context context){
        super(boundCenterBottom(defaultMarker));
        mContext = context;
}

The Context item appears to come into play later on in this class, in the onTap method:

@Override
protected boolean onTap(int index){
    OverlayItem item = mOverlays.get(index);
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.show();
    return true;
}

However, the tutorial doesn’t explain how AlertDialog.Builder works – it just kind of throws it out there. And it seems like understanding the purpose of this is critical to understanding why the Context object exists.

In the main (and only) activity for this tutorial, the following lines seem to be the ones that interact with the HelloItemizedOverlay class:

List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
**HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);**

GeoPoint point = new GeoPoint(19240000, -99120000);
OverlayItem overlayitem = new OverlayItem(point, "Hello World!", "Ciudad Mexico");

itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);

The line marked with ** is the line that references the constructor for the HelloItemizedOverlay class. However, that line turned out to produce a NullPointerException error in the onTap method, which makes sense because that method utilizes mContext, which is never given a value. After searching through StackOverflow, I found that this was an error in the tutorial, and that it could be fixed by changing the line to

**HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);**

Which, indeed, worked.

So my questions are:

What is Context? I wasn’t really able to find a clear and applicable answer on the internet.

Why and how is Context used in this tutorial and in the Google Maps set up in general?

What is up with the two constructors?

Thanks!

  • 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-27T20:19:59+00:00Added an answer on May 27, 2026 at 8:19 pm

    What is Context?

    Context is an ancestor class of Activity (and other classes). It provides access to things like resources. You often need to supply a Context to various methods and constructors. If you are in a component (e.g., a MapActivity), using this should suffice in most cases.

    Why and how is Context used in this tutorial and in the Google Maps set up in general?

    Your MapActivity inherits from Context.

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

Sidebar

Related Questions

I'm trying to design some bookmarklets right now, that connect back to a server
Right now I'm trying to figure out a way to do things smarter, and
Right now I am trying to call my model, and spit out its results
Right now I'm trying to create my own tiny MVC (just for practice and
Right now I'm trying desperately to get @font-face to work in my website. This
Right now I'm trying this: int a = round(n); where n is a double
I'm developing an object-oriented PHP website right now and am trying to determine the
Right now I have been trying to use Launchpad's API to write a small
Right now, what i'm trying to do is display some lists on a page
So right now I've developed an application that I'm trying to write an API

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.