android - myIntent.getStringExtra 返回空值?

标签 android android-intent

<分区>

当我尝试在切换 Activity 时发送带有 Intent 的字符串时,我遇到了一个奇怪的问题。

这是我在类 1 中所做的:

Intent myIntent = new Intent(SearchText.this, Search.class);  
myIntent.putExtra("searchx", spinnerselected);  
myIntent.putExtra("SearchText", input);  
startActivity(myIntent); 

第 2 类:

Intent myIntent = getIntent();   
searchText=myIntent.getStringExtra("SearchText");  
spinnerselectednumber=Integer.parseInt(myIntent.getStringExtra("searchx"));

并且在第二类中使用调试器,很明显其中有一个值 searchx .

尽管行 myIntent.getStringExtra("searchx") 返回 null

这是为什么?

最佳答案

尝试将 .ToString() 添加到 myIntent.putExtra("searchx", spinnerselected); 使其成为 myIntent.putExtra("searchx", spinnerselected.ToString()); 这对我总是有效

关于android - myIntent.getStringExtra 返回空值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5451117/

相关文章:

android - StartActivity 和 FragmentTransaction 的区别

java - 在android中执行蓝牙文件传输时出错

android - 从 Android 应用程序发送到 Nodejs 服务器的编码问题,解码后是否有空格?

android - 使用浏览器启动应用程序?

android - cordova android sql select返回长度1但没有行

android - 从捕获的 DownloadManager Intent 中检索文件路径

android - finish() 关闭应用程序而不是 Activity

android - 同时播放两首mp3歌曲

android - 屏幕方向更改后 fragment 重置

java - 检测到 NFC 标签后启动我的应用程序,然后显示结果