Activity on back pressed handle

577 views Asked by At

Activity launcher

I have three activities like Activity A - Activity B - Activity C . Activity launch through intent. When Activity C is launched and I click back button to get activity A with out handle back pressed. How can I get this?

3

There are 3 answers

0
zMabrook On

If you are in Activity C and you want to go back to Activity A without going to Activity B you should use flags.

Intent startActivityA = new Intent(ActivityC.this,ActivityA.class);
startActivityA.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startActivityA);
0
Charu On

When you are launching Activity C from B then after startActivity() method call finish() in Activity-B. It will remove Activity-B from activity-stack.

0
vaibhav-systematix On

while calling activity C from activity B, you can call finish() method after calling intent. see the syntax below.

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent=new Intent(B.this,C.Class);
    startActivity(intent);
    finish();
}