Android How to - Start Activity and Close








Question

We would like to know how to start Activity and Close.

Answer

//from   w w w  . j a v a  2 s .  co m
import android.app.Activity;
import android.content.Intent;

class ActivityUtils {

    public static void startActivityAndFinish(Activity packageContext,
            Class<?> cls) {
        Intent intent = new Intent(packageContext, cls);
        packageContext.startActivity(intent);
        packageContext.finish();

    }

    public static void startActivity(Activity packageContext, Class<?> cls) {
        Intent intent = new Intent(packageContext, cls);
        packageContext.startActivity(intent);

    }
}