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.clevertrail.mobile.Database_SavedTrails.java

public static int openSavedTrails(Activity activity) {
    JSONArray jsonArray = null;//from  ww w .j  ava2 s .c om
    Database_SavedTrails db = new Database_SavedTrails(activity);
    db.openToRead();

    //getJSONString() without an argument returns all saved trails
    String jsonString = db.getJSONString();

    try {
        jsonArray = new JSONArray(jsonString);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return R.string.error_corrupttrailindatabase;
    }

    db.close();

    //clear the traillist and then load it up with all the saved trails
    Object_TrailList.clearTrails();
    if (jsonArray != null && jsonArray.length() > 0) {
        int len = jsonArray.length();
        try {
            for (int i = 0; i < len && i < 20; ++i) {
                JSONObject trail = jsonArray.getJSONObject(i);
                //add trail information from the JSON
                Object_TrailList.addTrailWithJSON(trail);
            }
        } catch (JSONException e) {
            return R.string.error_corrupttrailindatabase;
        }
    }

    //prepare the extras for the saved trails activity (icon and title)
    int icon = R.drawable.ic_viewtrailtab_save_unselected;
    String title = "CleverTrail - Saved Trails";
    Intent i = new Intent(activity, Activity_ListTrails.class);
    i.putExtra("icon", icon);
    i.putExtra("title", title);
    activity.startActivity(i);

    return 0;
}

From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java

/**
 * // w  w  w  .ja v  a  2 s.com
 * @param act Activity
 * @param showCamera ???
 * @param l Listener
 */
public void pickMulti(Activity act, boolean showCamera, OnImagePickCompleteListener l) {
    //
    setSelectMode(Select_Mode.MODE_MULTI);
    setShouldShowCamera(showCamera);
    setOnImagePickCompleteListener(l);
    cropMode = false;
    act.startActivity(new Intent(act, ImagesGridActivity.class));
}

From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java

/**
 * ?// w ww. j a  v a 2 s  .c o m
 * @param act Activity
 * @param showCamera ???
 * @param l Listener
 */
public void pickSingle(Activity act, boolean showCamera, OnImagePickCompleteListener l) {
    //
    setSelectMode(Select_Mode.MODE_SINGLE);
    setShouldShowCamera(showCamera);
    setOnImagePickCompleteListener(l);
    cropMode = false;
    act.startActivity(new Intent(act, ImagesGridActivity.class));
}

From source file:com.auth0.lock.Lock.java

/**
 * Starts LockActivity from a given Activity
 *
 * @param activity from which LockActivity will be started
 */// w w  w. j  a v a  2 s. c om
public void loginFromActivity(Activity activity) {
    Intent loginIntent = new Intent(activity, LockActivity.class);
    activity.startActivity(loginIntent);
}

From source file:com.metinkale.prayerapp.utils.PermissionUtils.java

public void needNotificationPolicy(final Activity act) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        return;//from  w  ww  . ja v  a  2  s  . c om
    }
    NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE);
    pNotPolicy = nm.isNotificationPolicyAccessGranted();
    if (!pNotPolicy) {
        Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);

        PackageManager packageManager = act.getPackageManager();
        if (intent.resolveActivity(packageManager) != null) {
            act.startActivity(intent);
        } else {
            ActivityCompat.requestPermissions(act,
                    new String[] { Manifest.permission.ACCESS_NOTIFICATION_POLICY }, 0);
        }
    }
}

From source file:com.lcl6.cn.imagepickerl.AndroidImagePicker.java

/**
 * ???//w w w  . j  a v  a 2 s. c om
 * @param act
 * @param showCamera
 * @param cropSize
 * @param l
 */
public void pickAndCrop(Activity act, boolean showCamera, int cropSize, OnImageCropCompleteListener l) {
    setSelectMode(Select_Mode.MODE_SINGLE);
    setShouldShowCamera(showCamera);
    addOnImageCropCompleteListener(l);
    cropMode = true;
    this.cropSize = cropSize;

    act.startActivity(new Intent(act, ImagesGridActivity.class));
}

From source file:com.rks.musicx.misc.utils.Helper.java

/**
 * Start Activity//from   www  . j a  v a 2 s .  co m
 * @param context
 * @param sClass
 * @param <S>
 */
public static <S> void startActivity(Activity context, Class<S> sClass) {
    if (context == null) {
        return;
    }
    Intent intent = new Intent(context, sClass);
    context.startActivity(intent);
}

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

public static void openAbout(final Activity activity) {
    try {// w  ww .j a  v  a 2  s .  c  om
        PackageInfo pInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0);
        new MaterialDialog.Builder(activity).title(R.string.app_name).theme(Theme.DARK)
                .content(activity.getString(R.string.about_app_description, pInfo.versionName))
                .positiveText(R.string.website).negativeText(R.string.help)
                .callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(MaterialDialog dialog) {
                        super.onPositive(dialog);
                        String url = activity.getString(R.string.website_url);
                        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                        CustomTabsIntent customTabsIntent = builder.build();
                        try {
                            customTabsIntent.launchUrl(activity, Uri.parse(url));
                        } catch (Exception e) {
                            // There is no way to view the website.
                            activity.startActivity(new Intent(activity, HomepageWebViewActivity.class));
                        }
                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);
                        ActivityUtils.openIntroVoluntarily(activity);
                    }
                }).show();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.android.calendar.event.CreateEventDialogFragment.java

private void setDefaultCalendarView(Cursor cursor) {
    if (cursor == null || cursor.getCount() == 0) {
        // Create an error message for the user that, when clicked,
        // will exit this activity without saving the event.
        dismiss();/*from   w ww .  j av  a  2s  . c om*/
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.no_syncable_calendars).setIconAttribute(android.R.attr.alertDialogIcon)
                .setMessage(R.string.no_calendars_found)
                .setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        final Activity activity = getActivity();
                        if (activity != null) {
                            Intent nextIntent = new Intent(Settings.ACTION_ADD_ACCOUNT);
                            final String[] array = { "com.android.calendar" };
                            nextIntent.putExtra(Settings.EXTRA_AUTHORITIES, array);
                            nextIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                            activity.startActivity(nextIntent);
                        }
                    }
                }).setNegativeButton(android.R.string.no, null);
        builder.show();
        return;
    }

    String defaultCalendar = null;
    final Activity activity = getActivity();
    if (activity != null) {
        defaultCalendar = Utils.getSharedPreference(activity, GeneralPreferences.KEY_DEFAULT_CALENDAR,
                (String) null);
    } else {
        Log.e(TAG, "Activity is null, cannot load default calendar");
    }

    int calendarOwnerIndex = cursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT);
    int accountNameIndex = cursor.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME);
    int accountTypeIndex = cursor.getColumnIndexOrThrow(Calendars.ACCOUNT_TYPE);

    cursor.moveToPosition(-1);
    while (cursor.moveToNext()) {
        String calendarOwner = cursor.getString(calendarOwnerIndex);
        if (defaultCalendar == null) {
            // There is no stored default upon the first time running.  Use a primary
            // calendar in this case.
            if (calendarOwner != null && calendarOwner.equals(cursor.getString(accountNameIndex))
                    && !CalendarContract.ACCOUNT_TYPE_LOCAL.equals(cursor.getString(accountTypeIndex))) {
                setCalendarFields(cursor);
                return;
            }
        } else if (defaultCalendar.equals(calendarOwner)) {
            // Found the default calendar.
            setCalendarFields(cursor);
            return;
        }
    }
    cursor.moveToFirst();
    setCalendarFields(cursor);
}

From source file:com.project.qrypto.keymanagement.KeyManager.java

public void init(Activity context) throws InvalidCipherTextException, IOException {
    if (!storeLoaded) {
        SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
        internalStorage = preferences.getBoolean(USE_INTERNAL_STORAGE, true);
        passwordProtected = preferences.getBoolean(PASSWORD_PROTECTED, true);
        setupComplete = preferences.getBoolean(SETUP_COMPLETE, false);
        if (passwordProtected) {
            Intent intent = new Intent(context, SetupActivity.class);
            context.startActivity(intent);
        } else {/*  w w  w  .  jav  a2 s .c o m*/
            load(context);
        }
    }
}