【问题标题】:can not get extras from intent不能从意图中得到额外的东西
【发布时间】:2017-11-27 01:38:35
【问题描述】:

我试图从谷歌地图活动中获取纬度和经度,如果我尝试使用 getDoubleExtra 的 null 如果我正在使用 getStringExtra,我总是得到默认值 这是我在 Google 地图活动中的代码:

public void onOkClick(View v){                                        
    Toast.makeText(getApplicationContext(), "we will save the place",
            Toast.LENGTH_LONG).show();
    Intent back= this.getIntent();
    back.putExtra("latitude",latitudeB);
    back.putExtra("longitude",longitudeB);
    setResult(RESULT_OK,back);
    finish();

}

这是接收部分:

   protected void onActivityResult(int requestcode, int resultcode,Intent data){                   
    super.onActivityResult(requestcode,resultcode,data);
    if(resultcode==RESULT_OK&&requestcode==PLACE_PICKER_REQUEST){
        Bundle B=data.getExtras();
        String la=B.getString("latitude");
        String lo=data.getStringExtra("longitude");
        placee.setText(""+la+"   "+lo);
}
}

【问题讨论】:

  • 为什么不说Intent intent = new Intent();
  • onOkCLick 中的 latitudeB 类型是什么
  • 这是一个全局变量,现在可以使用了。谢谢!

标签: android google-maps android-intent


【解决方案1】:

当您尝试转换回调用活动时,您可以创建一个新 Intent 并相应地设置值:

public void onOkClick(View v){                                        
   Toast.makeText(getApplicationContext(), "we will save the place",
        Toast.LENGTH_LONG).show();
   Intent back= new Intent();
   back.putExtra("latitude",latitudeB);
   back.putExtra("longitude",longitudeB);
   setResult(RESULT_OK,back);
   finish();
 }

试试这个,让我知道结果如何;因为getIntent() 可以返回null!

一切顺利!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 2023-01-30
    相关资源
    最近更新 更多