How to add a menu to MapActivity?

I've got an app using MapActivity.onCreate() to initialize the map and show it on screen. Now I would like to add a menu to my app. From what I've found out I can't add a menu from MapActivity and need to use Activity (correct me if I'm wrong).

Now I have no idea how to "initialize" the map from my Activity-class.

And how would I have to fix the views, will I wrap my activity-layout around my Map-layout?


Asked by: Carina273 | Posted: 24-01-2022






Answer 1

MapActivity extends a regular Android Activity, so there's nothing irregular you should need to do to create a menu.

Just override the onCreateOptionsMenu method, as shown in the developers' guide.

Answered by: Victoria907 | Posted: 25-02-2022



Answer 2

MapActivity extends Activity, so you should be able to add a menu.

Answered by: David502 | Posted: 25-02-2022



Answer 3

MapActivity is a subclass of Activity, and thus you do it the same way as in any normal Activity (instructions here). I've been able to successfully create menus the same way in MapActivity as in a normal Activity.

Answered by: Sam771 | Posted: 25-02-2022



Answer 4

Make sure that it doesn't extend from FragmentActivity but from AppCompatActivity!

If that's the case, the onCreateOptionsMenu method will be called and you are able to overwrite it like this:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu); //"menu_main" is the XML-File in res
        return super.onCreateOptionsMenu(menu);
    }

Answered by: Adelaide757 | Posted: 25-02-2022



Similar questions

MapActivity class in android?

when i extends the MapActivity class it shows an error. error is: cant resolved datatype. why? how to add a maps.jar in my project? thanks.


MapActivity class in android?

when i extends the MapActivity class it shows an error. error is: cant resolved datatype. why? how to add a maps.jar in my project? thanks.


android - Strange activity stack behavior when using MapActivity

I have the following activity structure in my application A simple "splash screen" activity is started when the application is fired up (let's call it "Splash"). This activity starts the main activity when the user presses a button (I will call it "Main"). Main can in turn start two activities from the menu. The first activity presents a simple form (let's call this one "Form"), the second is a MapActivity...


android - MapView without extending MapActivity

Is there a way to display a MapView without extending MapActivity? I have other Activity class which I'm extending and I would prefer not to change that... I've seen that you can inflate using MapActivity, but didn't find any spec/examples on how to do it.


java - Is it possible to use a MapView without having to extend MapActivity?

Currently in my design I've got a base abstract class that all of my activities extend from, however I discovered recently that in order to use a MapView you need to make your activity extend MapActivity. Since Java does not have multiple inheritance I was wondering if there is any way I can use a MapView without having to recreate my design for my application. Thanks in advance for any help! Regards, cele...


android - Problem launching a MapActivity

My app force closes when I try to launch the same MapActivity from the HelloGoogleMaps tutorial. I am launching it from my main activity which is just a list: @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Intent i = new Intent(this, HelloGoogleMaps.class); startActivity(i); }


java - Resource usage in Google's MapActivity for Android

Does anyone happen to know if Google's MapActivity will eat up extra resources if an Activity does not use Google's MapView? The reason I ask it because I'd like to have a base activity class (which would extend MapActivity) for my activities in my application, but I don't want my resources to be eaten up when the user is in an activity that doesn't utilize Google's MapView. Thanks in advance for any help!


android - How can I return the location pressed to the MapActivity from an Overlay onTap method

I have an activity that has a button which opens a new MapActivity to select a location by tapping on the map. The map has an overlay that overrides the onTap method to get the location but I want to return that location to the previous activity but, I don't know how to return the geopoint to the mapactivity in order to call the setResult() and finish() methods, because I can't call them from the Overlay.onTap meth...


java - Switching from activity to MapActivity

Button showmapButton = (Button)findViewById(R.id.showmap); showmapButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(HomePage.this, ShowMap.class); intent.putExtra("username", value); startActivity(intent); } }); In my main menu i have a button 'ShowMap' Everytime i click on showmap my map will hi...


Cannot resolve MapActivity class on Android

I have an application which has 11 different activities. One of these activities is an extension of MapActivity (it is a map for data visualization). To get to this activity the user must first travel through the launch activity, then 3 other activities. The code to launch the MapActivity is: Intent i = new Intent(getBaseContext(), MapVis.class); i.putExtra("edu.uml.cs.isense.visualizations.session_list"...


android - MapActivity error: force close

I created a new MapActivity class MapProba. From main Activity I want to show MapActivity: on button click event I put this code: Intent myIntent = new Intent(this, com.art.mode.MapProba.class); startActivity(myIntent); But I receive force close error. In my xml file I use this code: <Li...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top