我相信我看到了问题。您正在尝试访问您的Array
但它是一个实例变量而不是静态变量,因此当您退出时它会被杀死Activity
。您可以将它们放在静态类中并以这种方式访问它们,或者传递String
变量通过你的Intent
,取决于您的需要。
如果您有以下价值String
当你离开时你需要MainActivity
那么我可能会通过你的Intent
。如果该值取决于您的另一个中的某些内容Activities
然后我会考虑将它放在一个单独的类中,但看起来这不是你需要的
Edit
你已经在这里这样做了,有点
Intent i = new Intent(MainActivity.this, resultScreen.class);
i.putExtra("display" , displayChoice);
Intent intent = new Intent(MainActivity.this,loadingScreen.class);
但你还没有开始Activity
那会得到String
i.putExtra("display" , displayChoice);
该线将经过String
with key "displpay"
和价值displayChoice
,虽然我认为该值是空的String
那时,但你没有开始Activity
。我不知道你的流程应该如何工作,但基本上你会做这样的事情
String displayChoice = "testValue"; // some arbitrary value--whatever you need to send
Intent i = new Intent(MainActivity.this, resultScreen.class); // create the Intent
i.putExtra("display" , displayChoice); // add the extra
startActivity(i); //start the Activity
然后获取里面的值resultScreen
in onCreate()
Intent recIntent = getIntent(); // get the Intent that started this Activity
String value = recIntent.getStringExtra("display"); // get the value using the key
// value now equals "testValue"