Android examples for android.app:Activity Navigation
Goes back to the specific activity if it was already created and clears stack on top of it
import android.app.Activity; import android.content.Context; import android.content.Intent; public class Main{ /**//from w ww . j a va 2 s . co m * Goes back to the specific activity if it was already created and clears stack * on top of it * @param context context to work in * @param activityToGoBack activity class to go back to */ public static void goBackTo(Context context, Class<? extends Activity> activityToGoBack) { Intent intent = new Intent(context, activityToGoBack); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(intent); } }