假设有两个Activity,A和B。首先用A启动B,比如:
Intent intent = new Intent();
intent.setClass(A.this, B.class);
startActivity(intent);
然后要让B给A传递一些数据过来,该怎么解决?
我用这个方法出现错误:(317): java.lang.NumberFormatException: unable to parse '' as integer
A中:
Intent intent = new Intent();
intent.setClass(BaiduMap.this, Interest.class);
startActivityForResult(intent, 0);B中:
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("keywords", keywords.getText().toString());//从EditText中取数据
bundle.putInt("range", Integer.parseInt(range.getText().toString()));//从EditText中取数据
intent.putExtras(bundle);
intent.setClass(Interest.this, BaiduMap.class);
Interest.this.setResult(RESULT_OK,intent);
Interest.this.finish();
求高手解答。android中Activity间的通信

解决方案 »

  1.   

    你在文本框中输入的字符不是Int类型,造成:数字格式异常:无法解析的整数
      

  2.   

    bundle.putInt("range", Integer.parseInt(range.getText().toString()));//从EditText中取数据
    你是不是在文本框输入的不是整数呀..
      

  3.   

    类型不一致了吧,楼主你不做下测试或者debug么?
      

  4.   

    B中intent.setClass(Interest.this, BaiduMap.class);
    不需要
    setResult就不需要这个,
      

  5.   

    转换格式异常
    A到B,B再到A,用activity自带的方法onActivityResult吧。
      

  6.   

    A启动B使用startActivityForResult在A中重写onActivityResult
      

  7.   

    现在所有的问题都已经解决,关于EditText中数据转换成int类型请见:
    http://bbs.csdn.net/topics/390425300或者http://blog.sina.com.cn/s/blog_a4dda2480101asy3.html
    两个进程间通信,第二个Activity给第一个Activity传递数据时第二个Activity中的setResult()方法中的第一个参数的值一定要比第一个Activity中startActivityForResult()方法的第二个参数的值要大,否则无法启动第一个Activity中的onActivityResult()方法。详情请见:http://blog.sina.com.cn/s/blog_a4dda2480101asyx.html
    非常感谢各位热心的道友的帮助!