Example usage for android.content Intent setClass

List of usage examples for android.content Intent setClass

Introduction

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

Prototype

public @NonNull Intent setClass(@NonNull Context packageContext, @NonNull Class<?> cls) 

Source Link

Document

Convenience for calling #setComponent(ComponentName) with the name returned by a Class object.

Usage

From source file:Main.java

public static void redirectActivity(Context fromClass, Class<?> toClass, Bundle bundle) {
    Intent intent = new Intent();
    intent.setClass(fromClass, toClass);
    if (null != bundle) {
        intent.putExtras(bundle);/*from w  w  w. j a v a2s  .  c  om*/
    }
    fromClass.startActivity(intent);

}

From source file:Main.java

public static void ActivitySkipWithObject(Context context, Class<?> toClass, String key, Serializable obj) {
    Intent intent = new Intent();
    intent.setClass(context, toClass);
    Bundle bundle = new Bundle();
    bundle.putSerializable(key, obj);/*from w  w  w  . j a  va2  s. c o  m*/
    intent.putExtras(bundle);
    //        int id =((IdObj)bundle.getSerializable("  ")).getId();
    context.startActivity(intent);
}

From source file:Main.java

public static void gotoActivity(Activity curActivity, Class<?> targetActivity, boolean finish) {
    Intent intent = new Intent();
    intent.setClass(curActivity, targetActivity);
    curActivity.startActivity(intent);/*from www.  j a v a 2 s .  c om*/
    //      curActivity.overridePendingTransition(R.anim.slide_left_in,
    //            R.anim.slide_left_out);

    if (finish) {
        curActivity.finish();
    }
}

From source file:Main.java

public static void goToActivity(Context packageContext, Class<?> targetActivityClass) {
    Intent intent = new Intent();
    intent.setClass(packageContext, targetActivityClass);
    packageContext.startActivity(intent);
}

From source file:Main.java

public static void startActivityWithObjectForResult(Context context, Class<?> toClass, String key,
        Serializable obj, int requestCode) {
    Intent intent = new Intent();
    intent.setClass(context, toClass);
    Bundle bundle = new Bundle();
    bundle.putSerializable(key, obj);/*from  w w w  .  ja v a  2 s.  c o m*/
    intent.putExtras(bundle);
    //        int id =((IdObj)bundle.getSerializable("  ")).getId();
    ((Activity) context).startActivityForResult(intent, requestCode);
}

From source file:Main.java

public static void startActivityNoHistory(Activity activity, Class classActivity) {
    Intent intent = new Intent();
    intent.setClass(activity, classActivity);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    activity.startActivity(intent);/*from w  ww  . j  av a2 s.  c  om*/
}

From source file:Main.java

public static void startActForResult(@NonNull Class cls, @NonNull Intent intent, int requestCode) {
    intent.setClass(mActivity, cls);
    mActivity.startActivityForResult(intent, requestCode);
}

From source file:Main.java

public static void takeMyselfToForeground(Context context, Class launcher) {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(context, launcher);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    context.startActivity(intent);//  w  w  w.j  ava 2  s . com
}

From source file:Main.java

public static void recreate(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        activity.recreate();/* w  ww.  jav a  2  s.c  om*/
    } else {
        Intent intent = activity.getIntent();
        intent.setClass(activity, activity.getClass());
        activity.startActivity(intent);
        activity.finish();
        activity.overridePendingTransition(0, 0);
    }
}

From source file:Main.java

/**
 * Create a precondition activity intent.
 * @param activity the original activity
 * @param preconditionActivityClazz the precondition activity's class
 * @return an intent which will launch the precondition activity.
 */// w w w  .  jav a  2 s . co  m
public static Intent createPreconditionIntent(Activity activity, Class preconditionActivityClazz) {
    Intent newIntent = new Intent();
    newIntent.setClass(activity, preconditionActivityClazz);
    newIntent.putExtra(EXTRA_WRAPPED_INTENT, activity.getIntent());
    return newIntent;
}