Here you can find the source of openActivity(Context packageContext, int flags, Map
Parameter | Description |
---|---|
packageContext | - Current context |
flags | - Intent flags to launch with the activity |
pairs | - parameters to the activity as a Bundle |
closeCurrentContext | - whether or not to close the current activity\service |
activity | - Activity to launch |
public static void openActivity(Context packageContext, int flags, Map<String, String> pairs, boolean closeCurrentContext, Class<?> activity)
//package com.java2s; import java.util.Map; import java.util.Map.Entry; import android.app.Activity; import android.app.Service; import android.content.Context; import android.content.Intent; import android.os.Bundle; public class Main { /**/*from w ww . j a va 2s . com*/ * Purpose - Launch an activity * * @param packageContext - Current context * @param flags - Intent flags to launch with the activity * @param pairs - parameters to the activity as a Bundle * @param closeCurrentContext - whether or not to close the current activity\service * @param activity - Activity to launch * * */ public static void openActivity(Context packageContext, int flags, Map<String, String> pairs, boolean closeCurrentContext, Class<?> activity) { if (packageContext == null) return; Intent intent = new Intent(packageContext, activity); //set the intent flags if any intent.setFlags(flags); if (pairs != null && !pairs.isEmpty()) { Bundle extras = new Bundle(); for (Entry<String, String> pair : pairs.entrySet()) { extras.putString(pair.getKey(), pair.getValue()); } intent.putExtras(extras); } //start the activity packageContext.startActivity(intent); //Close the current context if (closeCurrentContext) { if (packageContext instanceof Activity) { ((Activity) packageContext).finish(); } else if (packageContext instanceof Service) { ((Service) packageContext).stopSelf(); } } } }