Add and display intent in another class

-2

Well, I wanted to know how I can add this (intent) and how to start it at the end of the program in another Class.

public class Main2Activity extends AppCompatActivity implements View.OnClickListener{

    int points = 0;
    Button next;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        next = (Button) findViewById(R.id.next);
        next.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.option1:
                points = points + 0;
                break;
            case R.id.correctly:
                points = points + 1;
                break;
            case R.id.option3:
                points = points + 0;
                break;
            case R.id.option4:
                points = points + 0;
                break;
            case R.id.option5:
                points = points + 0;
                break;
        }
        if (next.isPressed()) {
            Intent intent = new Intent(this, Main3Activity.class);
            intent.putExtra("pontuação", points);
            startActivity(intent);
            apply(intent);
        }
    }
}
    
asked by anonymous 23.08.2017 / 05:27

1 answer

0

In the next activity:

Intent intent = getIntent();
if(intent != null){
    int soma = intent.getIntExtra("pontuação", 0);
    Log.i("tag", String.valueOf(soma));
}

Display soma as you prefer.

    
23.08.2017 / 13:14