0

我看过这个帖子:Android:如何在子活动中使用从父活动传递的数据?并准备好使用这种方法,但我想知道这是否已过时。从那时起,Android 取得了长足的进步,我不想以错误的方式做到这一点。

这仍然是应该使用的方法吗?

4

1 回答 1

0

这种方法非常好,今天仍在使用。还有另一种方法可以使用Bundle传递数据。捆绑包可以按如下方式使用

        Intent intent = new Intent(ActivityA.this, ActivityB.class);  
        Bundle b = new Bundle(); 
        b.putString("name", "abcd");
        b.putInt("value", 666);  
        //Add the set of extended data to the intent and start it
        intent.putExtras(b);
        startActivity(intent);  

并在其他活动中使用

    Bundle b = getIntent().getExtras(); 
    int value = b.getInt("value", 0);
    String name = b.getString("name");
于 2013-01-11T03:45:19.360 回答