简体   繁体   English

Android:意图不将数据获取到mainactivity

[英]Android: Intent not fetching data to the mainactivity

I have 2 Activities, from the second Activity 's OnCreate I am doing this: 我有2个活动,从第二个ActivityOnCreate开始:

setPassButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
            if(getPass1 == getPass2) {
                Intent gotoMain = new Intent(FirstRun.this, MainActivity.class);
                gotoMain.putExtra("getPass1", getPass1);
                startActivity(gotoMain);

In the first Activity , I am trying to fetch this getPass1 , but it always gives me -1 . 在第一个Activity ,我试图获取此getPass1 ,但它总是给我-1 What am I missing here? 我在这里想念什么? This is also in OnCreate of the MainActivity 这也在MainActivity OnCreate

Intent intent = getIntent();
iSelectedItem = intent.getIntExtra("getPass1", -1);
System.out.println("Password is " + iSelectedItem);

Try this: 尝试这个:

Intent intent = getIntent();
iSelectedItem = intent.getExtras().getInt("getPass1", -1);
System.out.println("Password is " + iSelectedItem);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM