传递整数活动和意图的机器人之间始终是造成零/空 [英] Passing Integer Between Activities and Intents in Android Is Always Resulting in Zero / Null

查看:152
本文介绍了传递整数活动和意图的机器人之间始终是造成零/空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过从我的主页活动两个整数(经度和纬度)到包含谷歌地图的一个实例,否则将标记的纬度和长提供的第二个活动。我的难题是,当我找回包的Map_Page活动我通过这个整数是始终为0,这是默认的,当他们空。有谁看到什么错得离谱?

我有以下的存储在一个按钮,单击OnClick方法。

 捆绑dataBundle =新包();

dataBundle.putInt(LatValue,39485000);
dataBundle.putInt(的longValue,-80142777);
意图myIntent =新意图();
myIntent.setClassName(com.name.tlc,com.name.tlc.map_page);
myIntent.putExtras(dataBundle);
startActivity(myIntent);
 


然后在我的map_page活动,我有以下的的onCreate回暖数据。

 捆绑额外= getIntent()getExtras()。
的System.out.println(获取意图做);
如果(临时演员!= NULL)
{
    的System.out.println(让我们的价值观);
    INT latValue = extras.getInt(latValue);
    INT的longValue = extras.getInt(的longValue);

    的System.out.println(latValue =+ latValue +的longValue =+的longValue);

}
 

解决方案

 的System.out.println(让我们的价值观);
INT latValue = extras.getInt(latValue);
INT的longValue = extras.getInt(的longValue);
 

不一样的

  myIntent.putExtra(LatValue,(INT)39485000);
myIntent.putExtra(的longValue,(int)的-80142777);
 

此外,它可能是因为你不守诚信的整个code一模一样的名字。 Java和Android的SDK是区分大小写

I'm attempting to pass two integers from my Main Page activity (a latitude and longitude) to a second activity that contains an instance of Google Maps that will place a marker at the lat and long provided. My conundrum is that when I retrieve the bundle in the Map_Page activity the integers I passed are always 0, which is the default when they are Null. Does anyone see anything glaringly wrong?

I have the following stored in a button click OnClick method.

Bundle dataBundle = new Bundle();

dataBundle.putInt("LatValue", 39485000);
dataBundle.putInt("LongValue", -80142777);
Intent myIntent = new Intent();
myIntent.setClassName("com.name.tlc", "com.name.tlc.map_page");
myIntent.putExtras(dataBundle);
startActivity(myIntent);


Then in my map_page activity I have the following in onCreate to pick up the data.

Bundle extras = getIntent().getExtras(); 
System.out.println("Get Intent done");
if(extras !=null)
{
    System.out.println("Let's get the values");
    int latValue = extras.getInt("latValue");
    int longValue = extras.getInt("longValue");

    System.out.println("latValue = " + latValue + " longValue = " + longValue);

}

解决方案

System.out.println("Let's get the values");
int latValue = extras.getInt("latValue");
int longValue = extras.getInt("longValue");

Not the same as

myIntent.putExtra("LatValue", (int)39485000);
myIntent.putExtra("LongValue", (int)-80142777);

Also it might be because you do not keep the name of the Int exactly the same throughout your code. Java and the Android SDK are Case-sensitive

这篇关于传递整数活动和意图的机器人之间始终是造成零/空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆