小编ore*_*man的帖子

getIntExtra始终返回默认值

我试图使用intent在活动之间传递一个整数.源活动使调用info.id成为ListView中的选定项.

Intent intent = new Intent(myActivity.this, newClass.class); 
intent.putExtra("selectedItem", info.id); 
this.startActivity(intent); 
Run Code Online (Sandbox Code Playgroud)

目标活动使用getIntent然后调用来检索intent

int iSelectedItem = intent.getIntExtra("selectedItem", -1); 
Run Code Online (Sandbox Code Playgroud)

iSelectedItem始终为-1而不是传递给putExtra的值.有人可以告诉我我做错了什么或者我是否误解了意图的使用?

android

17
推荐指数
2
解决办法
4万
查看次数

标签 统计

android ×1