I'm having an application for financial management, spending control for college, it's my first experience with android studio and the java language, but I'm already evolving a lot, I need to keep changing the TextView of the user's balance, the same in OnCreate has a method that brings from another activity a value to be treated according to what the user informs in the case spent or gained, works perfectly, but when I recreate the solution I end up losing the balance, I would like some help to keep the value of TextView even after it is closed. follow below my Acitivity onCreate where it has the method and TextView I want to keep. protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_home); Toolbar toolbar = (Toolbar) findViewById (R.id.toolbar); txtSaldo = (TextView) findViewById (R.id.txtSaldo); setSupportActionBar (toolbar); Intent intent = getIntent (); Bundle bundle = intent.getExtras (); if (bundle! = null) { String txt = bundle.getString ("txt"); String test = bundle.getString ("test");
if(teste!=null) {
if (teste.contains("+")) {
v2 = txt;
double vb = Double.parseDouble(v2);
v1 = txtSaldo.getText().toString();
double va = Double.parseDouble(v1);
double total = vb + va;
resultado = Double.toString(total);
txtSaldo.setText(resultado);
} else {
v2 = txt;
double vb = Double.parseDouble(v2);
v1 = txtSaldo.getText().toString();
double va = Double.parseDouble(v1);
double total = va - vb;
resultado = Double.toString(total);
txtSaldo.setText(resultado);
}
}
}
smartTabLayout = findViewById(R.id.smartTabLayout);
viewPager = findViewById(R.id.viewpager);
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getSupportFragmentManager(),
FragmentPagerItems.with(this)
.add("Últimos lançamentos", ListaFragment.class)
.add("Histórico Mês", HistoricoFragment.class)
.add("Gráficos", GraficoFragment.class)
.create()
);
viewPager.setAdapter(adapter);
smartTabLayout.setViewPager(viewPager);
}