Search code examples
androidandroid-activityandroid-lifecycle

Call new activity and destroy current one


I have three activities: A, B and C.

A is an intent to B and B is an intent to C,

When I finish the operation in C, I want to destroy C and go back to A, not B.

I've tried this:

finish();
B b = new B();
b.finish();

in C, doesn't work; And

finish();
B b = new B();
b.onDestroy();

in C, it results in a NullPointerException.

How do I achieve this?


Solution

  • Intent i = new Intent(MainActivity.this,SecondActivity.class);
    startActivity(i);
    finish();