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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:20:19+00:00 2026-05-21T17:20:19+00:00

please guide me how can i call the menu on the other activity Like

  • 0

please guide me how can i call the menu on the other activity

Like here is the main activity

package com.droidnova.android.howto.optionmenu;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class ControlMenu extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.settings:     
                Intent intent = new Intent(this, ShowSettings.class);
                  startActivity(intent);
            break;
            case R.id.services:     Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
                                break;
            case R.id.Quit: 

                new Thread(new Runnable() {
                    public void run() {                         
                        ControlMenu.this.finish();

                        // The following makes the Android Gods frown upon me
                        android.os.Process.killProcess(android.os.Process.myPid());
                        System.exit(0);
                    }
                }).start();
                break;
            default:    
            break;
        }
        return true;
    }
}

now i have make another activity in which i need to show the same menu in this

package com.droidnova.android.howto.optionmenu;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class ShowSettings extends Activity {

    Prefs myprefs = null;

    final String tag = "CH12:ShowSettings";

    AlertDialog.Builder adb;// = new AlertDialog.Builder(this);

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(R.layout.showsettings);

        this.myprefs = new Prefs(getApplicationContext());

        // load screen
        PopulateScreen();

        this.adb = new AlertDialog.Builder(this);

        final Button savebutton = (Button) findViewById(R.id.settingssave);

        // create anonymous click listener to handle the "save"
        savebutton.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                try {

                    // get the string and do something with it.

                    final EditText email = (EditText) findViewById(R.id.emailaddress);
                    if (email.getText().length() == 0) {

                        AlertDialog ad = ShowSettings.this.adb.create();
                        ad.setMessage("Please Enter Your Email Address");
                        ad.show();
                        return;
                    }

                    final EditText serverurl = (EditText) findViewById(R.id.serverurl);
                    if (serverurl.getText().length() == 0) {
                        AlertDialog ad = ShowSettings.this.adb.create();
                        ad.setMessage("Please Enter The Server URL");
                        ad.show();
                        return;
                    }

                    // save off values
                    ShowSettings.this.myprefs.setEmail(email.getText().toString());
                    ShowSettings.this.myprefs.setServer(serverurl.getText().toString());
                    ShowSettings.this.myprefs.save();

                    // we're done!
                    finish();
                } catch (Exception e) {
                    Log.i(ShowSettings.this.tag, "Failed to Save Settings [" + e.getMessage() + "]");
                }
            }
        });
    }

    private void PopulateScreen() {
        try {
            final EditText emailfield = (EditText) findViewById(R.id.emailaddress);
            final EditText serverurlfield = (EditText) findViewById(R.id.serverurl);

            emailfield.setText(this.myprefs.getEmail());
            serverurlfield.setText(this.myprefs.getServer());
        } catch (Exception e) {

        }
    }
}

what should i write in the above code so my menu can also appear over here .

  • 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-21T17:20:20+00:00Added an answer on May 21, 2026 at 5:20 pm

    Create the menu as an xml resource, then you can access it from everywhere. Check the documentation. If you need to pass a certain data from only one activity to the other, extending Application seems too much, given you could just pass the info as en extra in the Intent. Besides there are “dangers” in that way of doing things (because of the activity lyfecicle) so you should use SharedPreferences in that case (instead of creating an Application global variable).

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

Sidebar

Related Questions

Please can you people guide me how to make ajax call when scroll down
Please guide, in Android how can I pass my string (less then 160 char)
please guide me how can i call different activities in the case instead of
Can some one please guide me to understand which jar file i need to
Can you please guide me what is session and session variables? I don't need
Can someone please explain the below to me. First is how I call the
I'm new to Android development and I can't seem to find a good guide
Please guide what is meaning by Web is stateless in simple words ? Kindly
Please recommend some websites with a quick guide. MSDN is good but it's hard
A seemingly simple call returns an error, but I don't understand why. Can anyone

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.