我的主要活动包含几个单选按钮。它们是一个名为 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);
}}
提前致谢