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

  • Home
  • SEARCH
  • 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 7611823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:45:30+00:00 2026-05-31T01:45:30+00:00

I have an android program that launches an intent and passes a value to

  • 0

I have an android program that launches an intent and passes a value to the next activity. I have done this before and it worked perfectly. But on this occasion it is not passing the value. I have used toast messages to see what happening and I cant figure out whats going on. Another question is in my other program that the intent.putextra worked the code

       Intent i= new Intent(this,SpecialLocationDatabase.class);

worked but in this program this gave me an error: “Remove arguments from intent” so i had to code it like:

      Intent i= new Intent(Main.this,SpecialLocationDatabase.class);

my code is below. There are two activities Main and SpecialLocationDataBase:

   public class Main extends Activity {
   /** The activity that launches the intent and passes the value. */

TextView tv;

private SpecialLocationDatabaseHelper dbIngredientHelper=null;
private static final int ACTIVITY_CREATE=0;



@Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dbIngredientHelper = new SpecialLocationDatabaseHelper(this);
    dbIngredientHelper.createDatabase();


    final Button button1 = (Button) findViewById(R.id.button1);
    button1.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            long choice=1;
            Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
            i.putExtra("choice", choice);
            //Main.this.startActivity(i);
            startActivityForResult(i, ACTIVITY_CREATE);

            Toast.makeText(Main.this,
                    "Here is your choice " + choice + " clicked",
                    Toast.LENGTH_LONG).show(); 




        }
     });

     final Button button2 = (Button) findViewById(R.id.button2);
     button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            long choice=2;
            Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
            i.putExtra("choice", choice);
            Main.this.startActivity(i);


        }
    });

    final Button button3 = (Button) findViewById(R.id.button3);
    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            long choice=3;
            Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
            i.putExtra("choice", choice);
            Main.this.startActivity(i);


        }
    });

    final Button button4 = (Button) findViewById(R.id.button4);
    button4.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            long choice=4;
            Intent i= new Intent(Main.this,SpecialLocationDatabase.class);
                i.putExtra("choice", choice);
            Main.this.startActivity(i);


        }
    });



    public class SpecialLocationDatabase extends ListActivity {
     /** The activity that is supposed to get the value. */


private static final int ACTIVITY_CREATE=0;
    private static final int ACTIVITY_EDIT=1;
    private SpecialLocationDatabaseHelper mDbHelper=null;

    long choice;

    private static final int BEGIN_SEARCH_OPTION = Menu.FIRST;


    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.specialloction);

    mDbHelper=new SpecialLocationDatabaseHelper(this);
    mDbHelper.openRead();
    Bundle extras = getIntent().getExtras();
     choice = extras.getInt("choice");
        Toast.makeText(SpecialLocationDatabase.this,
                "NOw your choice " + choice + " clicked",
                Toast.LENGTH_LONG).show();
    fillData(choice);
    registerForContextMenu(getListView());

    ListView list = getListView();
    list.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) {




            return true;
        }
    });
  • 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-31T01:45:31+00:00Added an answer on May 31, 2026 at 1:45 am

    You put choice as long, but reading it as int, you need to change one of them, for example:

    long receivedChoice = extras.getLong("choice");
    

    Regarding your other question – since the second time the intent was created inside a inner class, this has to be fully qualified (e.g. Main.this) to make it implicit that you are passing the Activity’s this and not the listener’s this

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

Sidebar

Related Questions

In my Android program, I have some code that downloads a file. This works
I have an android program that I am making with 4 seekbars, and 4
I have been working on a Android Web Services program that uses a number
I have a program that I'm writing in Android using Eclipse. It has an
I have implemented an android program that can receive simple messages using the MJSIP,
Hi im new to android and I have a program that has a global
I have android.permission.READ_OWNER_DATA but I can't find any reliable code that would explain how
I have an Android project that branched into three different applications, app-1 , app-2
I have an android listview filled with items. Every item has a button. This
I have a minimal program that does little more than let me set two

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.