4
I would like to know how to store information, such as this variable:
int t = 0;
Let’s say that during the use of the application, the user did some operation that added + 5 in this variable.
How do I stop when the user closes the application, the value continue to be 5 in the next use, instead of going back to 0?
I want to store in a database the floats gf and mf.
My code :
package com.gustavo.sample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
    Button send;
    TextView say;
    EditText num;
    CheckBox g;
    CheckBox m;
    float gf = 0;
    float mf = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bacon();
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String counter = num.getText().toString();
                if (counter.equals("")) {
                    Toast.makeText(getApplicationContext(),
                            "Digite um valor numerico", Toast.LENGTH_SHORT)
                            .show();
                } else {
                    float counterAsFloat = Float.parseFloat(counter);
                    if (g.isChecked() && m.isChecked()) {
                        Toast.makeText(getApplicationContext(),
                                "Selecione apenas um checkbox",
                                Toast.LENGTH_SHORT).show();
                    } else if (m.isChecked()) {
                        mf = mf + counterAsFloat;
                        say.setText("Math " + Float.toString(mf));
                    } else if (g.isChecked()) {
                        gf = gf + counterAsFloat;
                        say.setText("Geo " + Float.toString(gf));
                    } else
                        Toast.makeText(getApplicationContext(),
                                "Selecione um checkbox", Toast.LENGTH_SHORT)
                                .show();
                }
            }
        });
    }
    private void bacon() {
        g = (CheckBox) findViewById(R.id.checkBox1);
        m = (CheckBox) findViewById(R.id.checkBox2);
        send = (Button) findViewById(R.id.button1);
        say = (TextView) findViewById(R.id.textView1);
        num = (EditText) findViewById(R.id.editText1);
    }
}
I lightly edited your question to make it easier for other users to find it. Make sure that’s what you want to know. If you prefer, you can [Dit] the question and leave it better, or even reverse my edition if it has not turned out good.
– Bacco
Thank you friend, I am beginner in the forum and still do not have much experience ...
– Dibai