Add and display Indtent in another class

Asked

Viewed 52 times

-2

Good wondered, how can I add this (Intent) and how to print 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);
        }
    }
}
  • Ola Gabriel,

  • From what I understand, you must be doing some quests app and if the person hits the answer, sum with the points you already have and that score is taken to another Activity?

1 answer

0

On the next Activity:

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

Display soma however you prefer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.