Android examples for android.app:Activity Start
launch Activity
import java.util.Map; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class Main { /**//from w w w. j av a2 s . c o m * Launch an Activity. * * @param context * The current Context or Activity that this method is called from. * @param activity * The new Activity to open. * @param closeCurrentActivity * whether or not the current activity should close. * @param params * Parameters to add to the intent as a Bundle. */ public static void launchActivity(Activity context, Class<? extends Activity> activity, boolean closeCurrentActivity, Map<String, String> params) { Intent intent = new Intent(context, activity); if (params != null) { Bundle bundle = new Bundle(); for (Map.Entry<String, String> param : params.entrySet()) { bundle.putString(param.getKey(), param.getValue()); } intent.putExtras(bundle); } context.startActivity(intent); if (closeCurrentActivity) { context.finish(); } } public static void launchActivity(Activity context, Class<? extends Activity> activity, boolean closeCurrentActivity) { launchActivity(context, activity, closeCurrentActivity, null); } }