jump from one Activity to another Activity - Android android.app

Android examples for android.app:Activity Navigation

Description

jump from one Activity to another Activity

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class Main {

  public static void jump(Context old, Class<?> cls, int requestCode, Bundle mBundle) {
    jump(old, cls, requestCode, mBundle, false);
  }/* w w  w  .  j a va  2 s . c o  m*/

  public static void jump(Context old, Class<?> cls, int requestCode) {
    jump(old, cls, requestCode, null);
  }

  public static void jump(Context old, Class<?> cls, int requestCode, Bundle mBundle, boolean clearTop) {
    Intent intent = new Intent();
    intent.setClass(old, cls);
    if (mBundle == null) {
      mBundle = new Bundle();

    }
    Activity oldActivity = (Activity) old;
    mBundle.putString("from", oldActivity.getClass().getSimpleName());
    intent.putExtras(mBundle);

    Activity activity = (Activity) old;
    if (clearTop) {
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      activity.finish();
    }
    activity.startActivityForResult(intent, requestCode);
  }


}

Related Tutorials