我有3个班级A,B,C。
A 类将 3 个值传递给 B 类,B 类将 3 个值传递给 C 类。在 CI 类中,如果我单击此返回按钮,则有一个返回按钮,我想恢复我的活动 B。
我是安卓新手;我对活动生命周期了解不多。提前致谢。
这是我的代码。
public class A extends Activity
{
EditText one,two,three;Button sub;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.one);
this.onWindowFocusChanged(true);
one=(EditText)findviewById(R.id.one);
two=(EditText)findviewById(R.id.one);
three=(EditText)findviewById(R.id.one);
addListenerOnButton();
}
public void addListenerOnButton()
{
// TODO Auto-generated method stub
sub.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(A.this, B.class);
Bundle b=new Bundle();
b.putString("one",one.getText().toString());
b.putString("two",two.getText().toString());
b.putString("three",three.getText().toString());
b.putExtras(b);
startActivity(i);
}
});
}
}
这是 B 类活动
public class B extends Activity
{
EditText one,two,three;Button sub;String one1,two1,three1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.two);
this.onWindowFocusChanged(true);
one=(EditText)findviewById(R.id.one);
two=(EditText)findviewById(R.id.one);
three=(EditText)findviewById(R.id.one);
Bundle b = this.getIntent().getExtras();
one1=b.getString("one");
one.setText(one1);
two1=b.getString("two");
two.setText(two1);
three1=b.getString("three");
three.setText(three1);
addListenerOnButton();
}
public void addListenerOnButton()
{
// TODO Auto-generated method stub
sub.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent i = new Intent(B.this, C.class);
Bundle b=new Bundle();
b.putString("one",one.getText().toString());
b.putString("two",two.getText().toString());
b.putString("three",three.getText().toString());
b.putExtras(b);
startActivity(i);
}
});
}
}
这是 C 类活动(应用程序崩溃的地方)
public class C extends Activity
{
EditText one,two,three;Button sub,back;String one1,two1,three1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.three);
this.onWindowFocusChanged(true);
one=(EditText)findviewById(R.id.one);
two=(EditText)findviewById(R.id.one);
three=(EditText)findviewById(R.id.one);
Bundle b = this.getIntent().getExtras();
one1=b.getString("one");
one.setText(one1);
two1=b.getString("two");
two.setText(two1);
three1=b.getString("three");
three.setText(three1);
addListenerOnButton();
}
public void addListenerOnButton()
{
back.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//Clicking back button i want to resume the activity b class but its getting crashed
Intent i = new Intent(C.this, B.class);
startActivity(i);
}
});
}
}
每当我单击此后退按钮时,应用程序就会崩溃,而不是恢复我的 Activity B。