Activity1 ... public int b = 0; public String S = ""; ... public void counter(){ b++; S = Integer.toString(b); } ... Activity2 tvCounter.setText(S); //S - подчеркнуто красным цветом 1 answer
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
|
Intentand 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