Android Utililty Methods Activity Start

List of utility methods to do Activity Start

Description

The list of methods to do Activity Start are organized into topic(s).

Method

voidgoToActivity(Context currentActivity, Class newClass)
Switches to the given class (which must be a subclass of Activity).
Intent newActivity = new Intent(currentActivity, newClass);
currentActivity.startActivity(newActivity);
voidgoToActivity(Context currentActivity, Class newClass, List extras)
go To Activity
Intent newActivity = new Intent(currentActivity, newClass);
if (extras != null) {
    NameValuePair thisExtra = null;
    for (int x = 0; x < extras.size(); x++) {
        thisExtra = extras.get(x);
        newActivity.putExtra(thisExtra.getName(),
                thisExtra.getValue());
currentActivity.startActivity(newActivity);
voidopenActivity(Context packageContext, int flags, Map pairs, boolean closeCurrentContext, Class activity)
Purpose - Launch an activity
if (packageContext == null)
    return;
Intent intent = new Intent(packageContext, activity);
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());
...
voidstartApkActivity(final Context ctx, String packageName)
start Apk Activity
PackageManager pm = ctx.getPackageManager();
PackageInfo pi;
try {
    pi = pm.getPackageInfo(packageName, 0);
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setPackage(pi.packageName);
    List<ResolveInfo> apps = pm.queryIntentActivities(intent, 0);
...
voidrestartActivity(final Activity activity)
Restart the activity smoothly
if (activity == null)
    return;
final int enter_anim = android.R.anim.fade_in;
final int exit_anim = android.R.anim.fade_out;
activity.overridePendingTransition(enter_anim, exit_anim);
activity.finish();
activity.overridePendingTransition(enter_anim, exit_anim);
activity.startActivity(activity.getIntent());
...
voidrestartPC(final Activity activity)
Restart the activity smoothly
if (activity == null)
    return;
final int enter_anim = android.R.anim.fade_in;
final int exit_anim = android.R.anim.fade_out;
activity.overridePendingTransition(enter_anim, exit_anim);
activity.finish();
activity.overridePendingTransition(enter_anim, exit_anim);
activity.startActivity(activity.getIntent());
...
voidstartActivity(Context context, Class activity)
start Activity
Intent intent = new Intent(context, activity);
context.startActivity(intent);
voidstartNewActivity(Class target, final Activity activity)
start New Activity
Intent intent = new Intent(activity, target);
activity.startActivity(intent);
voidprepare(Activity activity, int id, int width)
prepare
if (sCoverBitmap != null) {
    sCoverBitmap.recycle();
Rect rectgle = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
int statusBarHeight = rectgle.top;
ViewGroup v1 = (ViewGroup) activity.findViewById(id).getRootView();
...