1
Guys I’m making an application for financial management, spending control for college, is my first experience with android studio and the java language, but I’m already evolving enough, I need to keep changed Textview user 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 won, works perfectly, but when recreates the solution I end up losing the balance, I would like help to keep the value of Textview even after it is closed. follows down the onCreate of my Acitivity where has the method and the Textview that I wish to maintain. 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);
}
You need to save this information to a database and retrieve it when starting the app. Search for data persistence on Android.
– StatelessDev