0

我的主要活动包含几个单选按钮。它们是一个名为 config 的按钮。我想要做的是单击配置新活动将启动并显示选定的单选按钮文本。但是当我点击配置时,应用程序被强制关闭。我无法找出错误。我通过以下链接了解意图 1) http://www.androidaspect.com/2012/07/passing-data-using-intent-object.html 2) http://www.androidaspect.com/2012 /02/how-to-start-new-activity-using-intent.html 以下是主要活动的 onclick 代码:

configbtn.setOnClickListener(new Button.OnClickListener(){
        @Override
        public void onClick(View arg0) {            
            //Toast.makeText(getApplicationContext(), "You have clicked on 'Config'...", Toast.LENGTH_LONG).show();
            if(!mode.equals(""))
            {
            Intent i = new Intent("com.av.android.profiles.configActivity");
            Bundle myBundle = new Bundle();
            myBundle.putString("promode",mode);
            i.putExtras(myBundle);
            startActivityForResult(i, 1);
            }
             else
             {
                Toast.makeText(getApplicationContext(), "Please select profile mode to config...!", Toast.LENGTH_LONG).show();
             }

         }});

第二个活动的代码:

public class configActivity extends Activity{


Bundle myBundle1 = new Bundle();
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.config);
    String myName = null;       
    Bundle extras = getIntent().getExtras();
    if(extras != null)
    {
        myName = extras.getString("promode");
    }


    TextView tvData = (TextView) findViewById(R.id.tvData);
    tvData.setText(myName);
    }}

提前致谢

4

2 回答 2

1

采用

if(extras != null)
    {
        myName = extras.getString("promode");
    }

代替

if(extras != null)
    {
        myName = extras.getString("Name");
    }

因为你是promode作为关键传递而不是Name

于 2012-08-25T12:29:09.897 回答
0

尝试

Intent i = new Intent(CurrentActvity.this,configActivity.class);
Bundle myBundle = new Bundle();
myBundle.putString("promode",mode);
i.putExtras(myBundle);
startActivityForResult(i, 1);

configActivity在清单文件中声明。

<activity
            android:name=".configActivity" />

并使用myName = extras.getString("promode");

于 2012-08-25T12:29:16.127 回答