Example usage for android.content Intent putExtras

List of usage examples for android.content Intent putExtras

Introduction

In this page you can find the example usage for android.content Intent putExtras.

Prototype

public @NonNull Intent putExtras(@NonNull Bundle extras) 

Source Link

Document

Add a set of extended data to the intent.

Usage

From source file:Main.java

public static void openActivity(Activity activity, Class<?> pClass, Bundle pBundle, int requestCode,
        int enterAnim, int exitAnim) {
    if (null == activity)
        return;/* w  ww  .j  a  v a2  s. c o  m*/

    Intent intent = new Intent(activity, pClass);
    if (pBundle != null) {
        intent.putExtras(pBundle);
    }

    if (requestCode < 0) {
        activity.startActivity(intent);
    } else {
        activity.startActivityForResult(intent, requestCode);
    }

    if (enterAnim > 0 && exitAnim > 0) {
        activity.overridePendingTransition(enterAnim, exitAnim);
    }
}

From source file:com.app.cat.util.ApplicationContext.java

/**
 * Call an new intent to show up on screen with an given bundle.
 * @param aClass Class to shown from application context.
 * @param bundle Bundle to set init params.
 */// ww  w.j av a 2  s.c  om
public static void runIntentWithParams(Class aClass, Bundle bundle) {
    if (context != null) {
        Intent i = new Intent(context, aClass);
        i.putExtras(bundle);
        activity.startActivity(i);
    }
}

From source file:Main.java

/**
 * Helper method to recreate the Activity. This method should be called after a Locale change.
 * @param activity the Activity that will be recreated
 * @param animate a flag indicating if the recreation will be animated or not
 *///from   w  w w .  ja  v a2 s . c o m
public static void recreate(Activity activity, boolean animate) {
    Intent restartIntent = new Intent(activity, activity.getClass());

    Bundle extras = activity.getIntent().getExtras();
    if (extras != null) {
        restartIntent.putExtras(extras);
    }

    if (animate) {
        ActivityCompat.startActivity(activity, restartIntent, ActivityOptionsCompat
                .makeCustomAnimation(activity, android.R.anim.fade_in, android.R.anim.fade_out).toBundle());
    } else {
        activity.startActivity(restartIntent);
        activity.overridePendingTransition(0, 0);
    }

    activity.finish();

}

From source file:Main.java

public static void openActivity(Activity activity, Class<?> pClass, String pAction, Bundle pBundle,
        int requestCode) {
    if (null == activity)
        return;/*from   w  w w . ja va 2  s .c o  m*/

    Intent intent = new Intent(pAction);
    intent.setClass(activity, pClass);
    if (pBundle != null) {
        intent.putExtras(pBundle);
    }

    if (requestCode < 0) {
        activity.startActivity(intent);
    } else {
        activity.startActivityForResult(intent, requestCode);
    }
}

From source file:com.alex.utils.FragmentNavigator.java

public static void moveTo(FragmentManager fragmentManager, @IdRes int containerId,
        Class<? extends Fragment> fragment, boolean addToBackStack, Context context, @Nullable Bundle args) {
    final String tag = fragment.getName();
    Fragment current = fragmentManager.findFragmentById(containerId);
    Fragment target = fragmentManager.findFragmentByTag(tag);

    if (target == null) {
        try {//  ww w  .java  2  s  . c om
            target = Fragment.instantiate(context, fragment.getName(), args);
        } catch (Exception e) {
            // ignore
        }
        if (target == null) {
            return;
        }

        FragmentTransaction transaction = fragmentManager.beginTransaction();
        if (current == null) {
            transaction.add(containerId, target, tag);
        } else {
            transaction.replace(containerId, target, tag);
            transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            if (addToBackStack) {
                transaction.addToBackStack(tag);
            }
        }
        transaction.commit();
    } else {
        if (current == target) {
            return;
        }
        // set result
        Intent intent = new Intent();
        if (args != null) {
            intent.putExtras(args);
        }
        target.onActivityResult(REQUEST_CODE, Activity.RESULT_OK, intent);
        boolean result = fragmentManager.popBackStackImmediate(tag, 0);
        if (!result) {
            fragmentManager.popBackStackImmediate(0, POP_BACK_STACK_INCLUSIVE);
        }
    }
}

From source file:Main.java

/**
 * Converts a fragment arguments bundle into an intent.
 *///w  ww  .j a  va 2 s . co m
public static Intent fragmentArgumentsToIntent(Bundle arguments) {
    Intent intent = new Intent();
    if (arguments == null) {
        return intent;
    }

    final Uri data = arguments.getParcelable("_uri");
    if (data != null) {
        intent.setData(data);
    }

    intent.putExtras(arguments);
    intent.removeExtra("_uri");
    return intent;
}

From source file:Main.java

public static boolean startActivity(Activity a, String packageName, Bundle args, int flags) {
    PackageManager pm = a.getPackageManager();
    boolean result = true;
    try {/* www  .ja  v  a  2  s.  c  om*/
        Intent intent = pm.getLaunchIntentForPackage(packageName);
        if (null != intent) {
            intent.addFlags(flags);
            if (args != null)
                intent.putExtras(args);
            a.startActivity(intent);
        }
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = false;
    }
    return result;
}

From source file:Main.java

/**
 * Convert a fragment arguments bundle into an intent.
 *//*w  w w .  ja v  a  2 s  .  c o  m*/
public static Intent fragmentArgumentsToIntent(Bundle arguments) {
    Intent intent = new Intent();
    if (arguments == null) {
        return intent;
    }

    final Uri data = arguments.getParcelable(URI_KEY);
    if (data != null) {
        intent.setData(data);
    }

    intent.putExtras(arguments);
    intent.removeExtra(URI_KEY);
    return intent;
}

From source file:Main.java

public static boolean startActivityUsingScheme(Activity a, String scheme, Bundle args) {
    Uri uri = Uri.parse(scheme + "://");
    Intent intent = new Intent(Intent.ACTION_RUN, uri);
    boolean result = true;
    try {/*from  w  ww. j a  v a 2 s.  c  o m*/
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (args != null)
            intent.putExtras(args);
        a.startActivity(intent);
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = false;
    }
    return result;
}

From source file:Main.java

@SuppressLint("NewApi")
public static void sendSchemeForResultAddMediaStack(Fragment activity, String mediaActivityUrl, String url,
        int requestCode, Bundle bundle) {
    Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(mediaActivityUrl));
    intent.putExtra(TARGET_SCHEME_URI, url);
    if (bundle != null) {
        intent.putExtras(bundle);
    }/*w  w w . ja va  2  s. c  om*/

    activity.startActivityForResult(intent, requestCode);
}