I have created TWO screens which i will paste the code below.
`FirstScreen:` i have a button and when tap/click it will go to `SecondScreen`
`SecondScreen:` i have a button and when tap/click it will go to `FirstScreen`
//code://
public class FirstScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.btnPressMe);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent(Main.this, SecondScreen.class));
}
});
}
}
public class SecondScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.secondscreen);
Button btn = (Button)findViewById(R.id.btnGoToThirdScreen);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//startActivity(new Intent(Main.this, SecondScreen.class));
//HOW DO I GOT TO FIRST SCREEN????
}
});
}
}
if there is a better of way of doing please let me know. – Thanks.
If you want to go back to the first activity, you just need to finish the second one, not create new instance of the first activity, this is done like that:
To start the second activity from the first one, you should do: