Example usage for android.app Activity startActivity

List of usage examples for android.app Activity startActivity

Introduction

In this page you can find the example usage for android.app Activity startActivity.

Prototype

@Override
public void startActivity(Intent intent) 

Source Link

Document

Same as #startActivity(Intent,Bundle) with no options specified.

Usage

From source file:com.shafiq.mytwittle.view.DirectMessageActivity.java

public static void createAndStartActivity(Activity currentActivity, TwitterContentHandle contentHandle,
        long otherUserId, String otherUserScreenName) {

    Intent intent = new Intent(currentActivity, DirectMessageActivity.class);
    intent.putExtra(KEY_HANDLE_BASE, contentHandle);
    intent.putExtra(KEY_OTHER_USER_ID, otherUserId);
    intent.putExtra(KEY_OTHER_USER_SCREEN_NAME, otherUserScreenName);
    currentActivity.startActivity(intent);
}

From source file:Main.java

public static void showWifiSettings(final Activity activity, final Runnable yes, final Runnable no) {
    // check for internet connection
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setTitle("No Internet Connection");
    alertDialog.setMessage("Would you like to change settings ?");
    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            if (yes != null)
                yes.run();//from w  w w  . jav  a  2  s .c  om
        }
    });
    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            if (no != null)
                no.run();
        }
    });
    // Showing Alert Message
    alertDialog.show();
}

From source file:Main.java

public static void actionStart(Activity activity, Class cls, Bundle bundle, int... intentFlags) {
    Intent intent = new Intent(activity, cls);
    if (intentFlags != null) {
        for (int i = 0; i < intentFlags.length; i++) {
            if (intentFlags[i] != 0) {
                if (i == 0) {
                    intent.setFlags(intentFlags[i]);
                } else {
                    intent.addFlags(intentFlags[i]);
                }/*from  w ww  .  ja v  a 2 s .c o m*/
            }
        }
    }
    if (bundle != null) {
        intent.putExtras(bundle);
    }
    activity.startActivity(intent);
}

From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java

/**
 * activity//from   w w  w .j  a  va 2 s  .co  m
 * @param from ?activity
 * @param to activity
 * @param extras ??
 */
public static void changeActivity(Activity from, Class<?> to, Bundle extras) {
    // Intent intent = setIntent(from, to, extras);
    Intent intent = new Intent();
    if (extras != null)
        intent.putExtras(extras);
    intent.setClass(from.getBaseContext(), to);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    from.startActivity(intent);
    //from.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    from.overridePendingTransition(R.anim.enter_righttoleft, R.anim.exit_righttoleft);
}

From source file:Main.java

private static void shareAct(Activity act, String fileName, String text) {

    Uri uri = null;//from www. ja v  a2 s.c o m

    try {
        FileInputStream input = act.openFileInput(fileName);
        Bitmap bitmap = BitmapFactory.decodeStream(input);
        uri = Uri.parse(MediaStore.Images.Media.insertImage(act.getContentResolver(), bitmap, null, null));
        input.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
    shareIntent.setType("image/jpeg");
    act.startActivity(Intent.createChooser(shareIntent, act.getTitle()));
}

From source file:Main.java

/**
 * Save a media in the downloads directory and offer to open it with a third party application.
 * @param activity the activity/*ww  w .j ava 2  s . co m*/
 * @param savedMediaPath the media path
 * @param mimeType the media mime type.
 */
public static void openMedia(final Activity activity, final String savedMediaPath, final String mimeType) {
    if ((null != activity) && (null != savedMediaPath)) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    File file = new File(savedMediaPath);
                    Intent intent = new Intent();
                    intent.setAction(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(file), mimeType);
                    activity.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(activity, e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:com.code19.library.SystemUtils.java

public static void callPhone(Activity activity, String phoneNumber) {
    if (activity != null && !TextUtils.isEmpty(phoneNumber)) {
        if (ActivityCompat.checkSelfPermission(activity,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }/*  w  w  w .j  a  va 2s . co m*/
        activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));
    }
}

From source file:com.android.contacts.activities.RequestPermissionsActivityBase.java

protected static boolean startPermissionActivity(Activity activity, String[] requiredPermissions,
        boolean isCallerSelf, Class<?> newActivityClass) {
    if (!hasPermissions(activity, requiredPermissions)) {
        final Intent intent = new Intent(activity, newActivityClass);
        activity.getIntent().putExtra(EXTRA_STARTED_PERMISSIONS_ACTIVITY, true);
        intent.putExtra(PREVIOUS_ACTIVITY_INTENT, activity.getIntent());
        intent.putExtra(EXTRA_IS_CALLER_SELF, isCallerSelf);
        activity.startActivity(intent);
        activity.finish();//w w  w .  j  a  v a  2  s.c  om
        return true;
    }

    // Account type initialization must be delayed until the Contacts permission group
    // has been granted (since GET_ACCOUNTS) falls under that groups.  Previously it
    // was initialized in ContactApplication which would cause problems as
    // AccountManager.getAccounts would return an empty array. See b/22690336
    AccountTypeManager.getInstance(activity);

    return false;
}

From source file:Main.java

/** Launch a SMS intent if the device is capable.
 *
 * @param activity The parent activity (for context)
 * @param number The number to sms (not the full URI)
 * @param text The sms body//from   ww w  .  java 2s.  c  o m
 */
public static void launchSmsIntent(final Activity activity, String number, String text) {
    Log.i(LOG_TAG, "Launch SMS intent to " + number);
    // create sms intent
    Uri smsUri = Uri.parse("smsto:" + number);
    Intent smsIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
    smsIntent.putExtra("sms_body", text);
    // make sure there is an activity which can handle the intent.
    PackageManager smspackageManager = activity.getPackageManager();
    List<ResolveInfo> smsresolveInfos = smspackageManager.queryIntentActivities(smsIntent, 0);
    if (smsresolveInfos.size() > 0) {
        activity.startActivity(smsIntent);
    }
}

From source file:com.felkertech.n.ActivityUtils.java

public static void openIntroVoluntarily(Activity activity) {
    activity.startActivity(new Intent(activity, Intro.class));
    activity.finish();//w  ww .  j  a v  a 2s.c  om
}