java - 在两个 Activity 之间传递 int

标签 java android variables integer

我正在尝试在两个 Activity 之间传递 int 值。在第一个 Activity 中,我编写了代码:

Class nextView = Class.forName("com.test.NextFile");                    
Intent nextIntentTest = new Intent(CurrentFile.this, NextFile.class);
nextIntentTest.putExtra("passingName",nameofvar);
startActivity(nextIntentTest);

并且,在第二个 Activity 中,

Intent intentTest = this.getIntent();
int counter = intentTest.getIntExtra("passingName",-1);

我不知道为什么,但我总是得到默认值(-1)。我对其他类和变量做了几乎相同的事情,一切都很好。也许问题出在 public class NextFile extends ListActivity 而不是 public class NextFile extends Avtivity

有人可以帮助我吗?

最佳答案

尝试

    Bundle c = new Bundle();

    c.putInt("passingName",nameofvar);
     yourintent.putExtras(c);

发布值

    Bundle b = getIntent().getExtras();
    int counter = b.getInt("passingName");  to retrieve it

关于java - 在两个 Activity 之间传递 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16609735/

相关文章:

java - 使用java的linux操作系统的USB检测

java - 获取单元格apache poi的名称

android - 无法设置android :visibility programmatically for a button using binding?

java - 无法读取另一个可分割对象中的可分割对象

java - 使用 CardDAV 从 Java 应用程序共享通讯录

java - 为什么从变量获取值比从数组获取值更受欢迎?

java - "Redraw"LinearLayout View 更改选项

java - 关于服务、Daos 及其之间 - 初学者的困境

java - 分析方法内部的变量。 JavaParser/ANTLR 或其他?

传递到各个动画的各个元素的 javascript 变量