Activity1 ... public int b = 0; public String S = ""; ... public void counter(){ b++; S = Integer.toString(b); } ... Activity2 tvCounter.setText(S); //S - подчеркнуто красным цветом 
  • yes, cache the value and pull it out of another asset and don’t bother the head - iFr0z
  • Thanks for the answer, can you give more details? A code fragment, if not difficult - Piter
  • google sharedpref, a bunch of examples will be both strings and int stores - iFr0z
  • you have an int, a string with an access identifier public, so inherit them, activity1 extends activity2, and activity2 extentds appcompattivity - iFr0z
  • @ iFr0z you teach now :). Between activations, data is transmitted through Intent and only this way, otherwise there will be problems, since no one guarantees the existence of activations that are not on the screen, as well as its fields - your way is the direct route to NPE - pavlofff

1 answer 1

 Intent i = new Intent(getApplicationContext(), NewActivity.class); i.putExtra("new_variable_name","value"); startActivity(i); 

In the new Activity, get the values ​​as follows:

 Bundle extras = getIntent().getExtras(); if (extras != null) { String value = extras.getString("new_variable_name"); } 
  • There is a detailed answer - Piter
  • String data = "This data must be transferred"; Intent i = new Intent(MainActivity.this, SecondActitviy.class); i.putExtra("testNameData", data); startActivity(i); And in the second activation, the getIntent method is called and the data is pulled out using the specified key. For example: String data = getIntent().getExtras().getString("testNameData"); - Sergiyss