It should work but it does not. I have an application with some activities. In example activity A and B. Order is A ->(some operation)->B->(some operation)->A... I start a new activities in this way:
//onClick method in A Activity
public void goToB(View view) {
Intent intent = new Intent(this,BActivity.class);
startActivity(intent);
finish();
}
//onClick method in B Activity
public void goToA(View view) {
Intent intent = new Intent(this,AActivity.class);
startActivity(intent);
finish();
}
I want to finish previous activities, so this is not solution in my case. I checked some answers here, in stackoverflow but they does not help in here.
Logcat says:
java.lang.IllegalStateException: Could not execute method of the activity
at some places
Caused by: java.lang.reflect.InvocationTargetException
at some places
Caused by: java.lang.IndexOutOfBoundsException
at some places
Has anyone an idea what I am doing wrong? I think it's quite simple thing to do, but maybe I am misunderstanding finish() or startActivity() methods.
EDIT: One thing I forgot: starting a new activity works "in forward", so from A->B. From B->A it crashes.