-6

I have two activities, one is a clicker game (where you click a button and the textView displays an int (increasing per click). The other activity is where I display that int. I've tried many times of different ways of how to pass this data to the next activity, however nothing seemed to work. I assume that this could be because this int does not stay the same, and is constantly changing. Could anyone suggest what to do?

Clicker:

    Intent getNumber = new Intent(this, Shop.class);

    getNumber.putExtra("passedMoney", clicks);

    startActivity(getNumber);

Stats:

    Intent getNumber = getIntent();

    int clicks = getNumber.getIntExtra("passedMoney", 0);

clicks is the int, which is 0.

Thanks in advance :)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Miguel P.
  • 1,007
  • 7
  • 13
  • 4
    Possible duplicate of [How to pass integer from one activity to another?](https://stackoverflow.com/questions/7074097/how-to-pass-integer-from-one-activity-to-another) , make sure you have the data when you got to next activity – Pavneet_Singh Oct 26 '17 at 08:20
  • Hey put some code! – Xenolion Oct 26 '17 at 08:20
  • You need to [edit] your question to show what you've tried, and explain exactly how it's failing. Passing data to another `Activity` is a pretty standard operation, and if you can't get any of the numerous examples available working, it's unlikely that users repeating them here will help you to solve your problem. – Mike M. Oct 26 '17 at 08:21
  • I would've just did some research on it, however the int is does not have the same value (as when you click the button it changes) – Miguel P. Oct 26 '17 at 08:21
  • @Thy_Great mean you are not sending the updated value – Pavneet_Singh Oct 26 '17 at 08:23
  • That could be it, but even when I click the button a couple of times and move on to the next activity to check my stats, I receive an int value of '0' – Miguel P. Oct 26 '17 at 08:24
  • show code of `Clicker` activity – shinilms Oct 26 '17 at 09:05

1 Answers1

1

Send data on click

startActivity(new Intent(vContext, OtherActivity.class).getIntExtra("number", itemData));

How to get data

int pos = getIntent().getIntExtra("number", 0);