情况1:
主要活动 :
public class MainActivity extends Activity implements View.OnClickListener {
button add;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youeLayout);
add = (Button) findViewById(R.id.buttonIdName);
add.setOnClickListener(R.id.buttonIdName)
public void onClick(View v) {
// TODO Auto-generated method stub
Intent data = new Intent(MainActivity.this,PreferenceActivity.class);
startActivity(data);
}
和 PreferenceActivity 的相同代码只需将 onClick() 方法更改为您想要的适当类
在 helpActivity: 添加 onBackPressed() 方法,如下所示:
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Intent youeIntentName = new Intent(HelpActivity.this,MainActivity.class);
startActivity(youeIntentName);
}
案例#2:
当用户从 MainActivity 转到 PreferenceActivity 后按下返回时,您无需更改任何内容,他将返回 MAinActivity 等等