public class Settings extends AppCompatActivity {
private EditText one, two;
private TextView result;
private Button save;
Integer perevod;
int in;
int in1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
one = (EditText) findViewById(R.id.editTextOne);
two = (EditText) findViewById(R.id.editTextTwo);
save =(Button) findViewById(R.id.button);
result = (TextView) findViewById(R.id.textView);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
int in2 = prefs.getInt("in",0);
one.setText(""+ in2);
int in3 = prefs.getInt("in1",0);
two.setText(""+ in3);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int number1 = Integer.parseInt(one.getText().toString());
int number2 = Integer.parseInt(two.getText().toString());
int sum = number1 / number2;
result.setText(String.valueOf(sum));
in = Integer.parseInt(one.getText().toString());
in1 = Integer.parseInt(two.getText().toString());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Settings.this);
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("in",in);
editor.putInt("in1",in1);
editor.apply();
Intent i = new Intent(Settings.this,Menu.class);
i.putExtra("in",in);
startActivity(i);
}
});
}
}
Это где находятся 2 числа, одно число я перемещаю в другой класс и мне его там нужно сохранить
Вот другой класс:
public class Menu extends AppCompatActivity {
TextView txtName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
txtName = (TextView) findViewById(R.id.Name);
int in = getIntent().getIntExtra("in",0);
txtName.setText(String.valueOf(in));
}
}