2011-10-14 49 views
0

即时尝试从一个活动到另一个一次发送两个捆绑,即时通讯没有运气..我可以发送捆绑确定,但是当我尝试两个发送两个我得到一个空指针。 继承人我的代码:立即发送多个包

Activity A, 
     @Override 
    protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TextView name = (TextView) v.findViewById(R.id.label2); 
     TextView number1 = (TextView) v.findViewById(R.id.label); 
     Intent i = new Intent(this, options_Page.class); 
    // Bundle bundle2 = new Bundle(); 
     Bundle bundle1 = new Bundle(); 
     bundle1.putString("title", number1.getText().toString()); 
    // bundle2.putString("title2", name.getText().toString()); 
     i.putExtras(bundle1); 
    // i.putExtras(bundle2); 
     startActivity(i); 

Activity B, 
        Bundle bundle1 = this.getIntent().getExtras(); 
    // Bundle bundle2 = this.getIntent().getExtras(); 
     String title = bundle1.getString("title"); 
    // String title2 = bundle2.getString("title2"); 
     ((TextView) findViewById(R.id.tvnumber)).setText(title); 
    // ((TextView) findViewById(R.id.tvname)).setText(title2); 

使用此代码,因为它是现在它发送一个包(数量)没有问题,如果有人知道我怎么可以给对方(名称),将真正帮助我。 在此先感谢...

+0

你为什么要2包? – user370305

+0

即时通讯不知道是否需要两个捆绑,我必须在列表中的一个活动名称和编号,我需要发送到另一个活动。谢谢 – steo

回答

4

您可以send more then one bundle但您的需求,从目前的情况下,你不需要它,只需使用一个,

试试这个,没有必要为2束,

在活性的,

Intent i = new Intent(this, options_Page.class); 
    i.putExtras("title", number1.getText().toString()); 
    i.putExtras("number", number2.getText().toString()); 
    startActivity(i); 

在活动B,

String value1 = getIntent().getExtras("title"); 
    String value2 = getIntent().getExtras("number"); 

Bundle extras = getIntent().getExtras(); 
    if (extras == null) { 
     return; 
    } 
    String value1 = extras.getString("title"); 
    String value2 = extras.getString("number"); 

谢谢。

+0

谢谢你的工作! – steo

2

首先,你不需要通过两个捆绑,但对于你的问题,我在我的末尾检查它,你can pass 2 or more than 2 bundle

你需要提取束值是这样的:

Bundle bundle1 = getIntent().getBundleExtra("bun1"); 
boolean value1 = bundle1.getBoolean("value1"); 
Bundle bundle2 = getIntent().getBundleExtra("bun2"); 
boolean value2 = bundle2.getBoolean("value2");