I have implemented this way and it works.It is much easier than all that is reported.
We have two activities : one is the main and another is the secondary.
In secondary activity, which is where we want to end the main activity , define the following variable:
public static Activity ACTIVIDAD;
And then the following method:
public static void enlaceActividadPrincipal(Activity actividad)
{
tuActividad.ACTIVIDAD=actividad;
}
Then, in your main activity from the onCreate
method , you make the call:
actividadSecundaria.enlaceActividadPrincipal(this);
Now, you're in control. Now, from your secondary activity, you can complete the main activity. Finish calling the function, like this:
ACTIVIDAD.finish();