how to pass value data between classes/activity in Android?

后端 未结 6 2013
情书的邮戳
情书的邮戳 2021-01-03 13:12

For example i have activity1, activity2, activity3 and lastly valueAllActivity? how do I pass the data from activity1, activity2, activity3 to --> valueAllActivity?

6条回答
  •  半阙折子戏
    2021-01-03 13:25

    I used a method in an activity to call another activity. It starts a game with two variables (resume and number of players).

    private void MethodToCallAnotherActivity(int resume, int players) {     
        Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
        intent.putExtra(NextActivity.RESUME, resume);
        intent.putExtra(NextActivity.PLAYERS, players);
        startActivity(intent);
    }
    

    in the 'onCreate' of the NextActivity, I used

    int resume = getIntent().getIntExtra(Game.RESUME, 1);
    

    to read the variable I wanted.

    Good luck!

提交回复
热议问题