NITHIN SUHAS
NITHIN SUHAS

Reputation: 73

getIntExtra always returns default

Please help me I don't understand what is wrong with this.. the value of k in called activity is always one.

My Calling activity code

            pos_st = position;
            Intent newActivity = new Intent(branch.this, BranchInfo.class);
            lk= idnum[pos_st];
            int x=Integer.parseInt(lk);
            newActivity.putExtra("idnumber",x);
            Toast.makeText(getApplicationContext(), "X :" + x, Toast.LENGTH_LONG).show();
            startActivity(newActivity);

Called Activity

Intent intent = new Intent();
int k =intent.getIntExtra("idnumber",1);

Upvotes: 1

Views: 1511

Answers (1)

George Mulligan
George Mulligan

Reputation: 11903

You do not want to create a new Intent() in the called activity.

Instead try the following to get the same Intent that was used to start the Activity:

Intent intent = getIntent();
int k = intent.getIntExtra("idnumber", 1);

Upvotes: 3

Related Questions