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:Main.java

public static void mail(Activity activity, String email, String subject, String content) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");

    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { email });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);

    if (content != null) {
        intent.putExtra(Intent.EXTRA_TEXT, content);
    }// ww w  .j  a  va  2s.c  o m

    final PackageManager manager = activity.getPackageManager();
    final List<ResolveInfo> matches = manager.queryIntentActivities(intent, 0);

    for (ResolveInfo info : matches) {
        if (info.activityInfo.packageName.endsWith(".gm")
                || info.activityInfo.name.toLowerCase().contains("gmail")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        } else if (info.activityInfo.packageName.endsWith(".email")
                || info.activityInfo.name.toLowerCase().contains("email")) {
            intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        }
    }

    activity.startActivity(intent);
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * Given an Intent, restarts the app and launches a startActivity to that intent.
 * The flags NEW_TASK and CLEAR_TASK are set if the Intent does not have them, to ensure
 * the app stack is fully cleared./*from  ww  w . j av  a2  s .  c  o  m*/
 * If an event listener is provided, the restart app event is invoked.
 * Must only be used from your error activity.
 *
 * @param activity      The current error activity. Must not be null.
 * @param intent        The Intent. Must not be null.
 * @param eventListener The event listener as obtained by calling getEventListenerFromIntent.
 */
public static void restartApplicationWithIntent(Activity activity, Intent intent, EventListener eventListener) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    if (eventListener != null) {
        eventListener.onRestartAppFromErrorActivity();
    }
    activity.finish();
    activity.startActivity(intent);
    killCurrentProcess();
}

From source file:co.edu.uniajc.vtf.content.controller.ARLauncherController.java

public void navigateToARView() {
    Activity loActivity = ((Fragment) this.coView).getActivity();
    Intent loIntent = new Intent(loActivity, ARViewActivity.class);
    loActivity.startActivity(loIntent);
}

From source file:fr.cph.chicago.util.Util.java

/**
 * Function to show settings alert dialog
 *///w  ww.j av  a  2 s  .c  om
static void showSettingsAlert(@NonNull final Activity activity) {
    new Thread() {
        public void run() {
            activity.runOnUiThread(() -> {
                final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                alertDialogBuilder.setTitle("GPS settings");
                alertDialogBuilder.setMessage(
                        "GPS is not enabled. Do you want to go to settings main.java.fr.cph.chicago.res.menu?");
                alertDialogBuilder.setCancelable(false).setPositiveButton("Yes", (dialog, id) -> {
                    final Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    activity.startActivity(intent);
                }).setNegativeButton("No", (dialog, id) -> dialog.cancel());
                final AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            });
        }
    }.start();
}

From source file:WebviewFallback.java

@Override
public void openUri(Activity activity, Uri uri) {
    Intent intent = new Intent(activity, WebViewActivity.class);
    intent.putExtra(WebViewActivity.EXTRA_URL, uri.toString());
    activity.startActivity(intent);
}

From source file:Main.java

public static void navigateUp(Activity activity, Bundle extras) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (upIntent != null) {
        if (extras != null) {
            upIntent.putExtras(extras);//www  .  ja  va  2 s  .  co m
        }
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(activity)
                    // Add all of this activity's parents to the back stack.
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent.
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            // According to http://stackoverflow.com/a/14792752/2420519
            //NavUtils.navigateUpTo(activity, upIntent);
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(upIntent);
        }
    }
    activity.finish();
}

From source file:com.mediatek.contacts.activities.ActivitiesUtils.java

public static boolean doImportExport(Activity activity) {
    Log.i(TAG, "[doImportExport]...");
    if (MultiChoiceService.isProcessing(MultiChoiceService.TYPE_DELETE)) {
        Toast.makeText(activity, R.string.contact_delete_all_tips, Toast.LENGTH_SHORT).show();
        return true;
    }//from ww w.j  ava2s  .c  o  m
    final Intent intent = new Intent(activity, ContactImportExportActivity.class);

    /* add callingActivity extra for enter ContactImportExportActivity from PeopleActivity,
     * cause by Dialer can hung up ContactImportExportActivity so we should distinguish which
     * Activity start ContactImportExportActivity by using callingActivity.@{
     */
    intent.putExtra(VCardCommonArguments.ARG_CALLING_ACTIVITY, PeopleActivity.class.getName());
    //@}

    activity.startActivity(intent);
    return true;
}

From source file:com.forrestguice.suntimeswidget.AlarmDialog.java

public static void scheduleAlarm(Activity context, String label, Calendar calendar) {
    if (calendar == null)
        return;/*from  w  w  w. j  ava2 s  . c o  m*/

    Calendar alarm = new GregorianCalendar(TimeZone.getDefault());
    alarm.setTimeInMillis(calendar.getTimeInMillis());
    int hour = alarm.get(Calendar.HOUR_OF_DAY);
    int minutes = alarm.get(Calendar.MINUTE);

    Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
    alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, label);
    alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, hour);
    alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);

    if (alarmIntent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(alarmIntent);
    }
}

From source file:com.diusrex.update.Update.java

public boolean execute(String className, JSONArray args, CallbackContext callbackContext) throws JSONException {
    Activity activity = this.cordova.getActivity();
    final String appPackageName = activity.getPackageName();
    try {//w w  w.j  ava  2 s  . c o  m
        activity.startActivity(
                new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
    } catch (android.content.ActivityNotFoundException anfe) {
        activity.startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
    }

    boolean quitApp = args.getBoolean(0);
    if (quitApp) {
        activity.finish();
    }

    return true;
}

From source file:com.openlocationcode.android.main.WelcomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Second argument is the default to use if the preference can't be found
    int savedVersionCode = prefs.getInt(WELCOME_VERSION_CODE_SHOWN_PREF, 0);
    int appVersionCode = 0;
    try {//ww w  .j  ava 2 s.co  m
        appVersionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException nnfe) {
        Log.w(TAG, "Exception getting appVersionCode : " + nnfe);
    }

    final Intent intent = new Intent(this, MainActivity.class);
    final Activity activity = this;

    if (appVersionCode == savedVersionCode) {
        activity.startActivity(intent);
        activity.finish();
    } else {
        Log.i(TAG, "Starting welcome page");
        setContentView(R.layout.welcome);

        // Increase the margin on the image to account for the translucent status bar.
        ImageView welcomeImage = (ImageView) findViewById(R.id.welcome_image);
        LayoutParams layoutParams = (LayoutParams) welcomeImage.getLayoutParams();
        layoutParams.topMargin = layoutParams.topMargin + MainActivity.getStatusBarHeight(this);
        welcomeImage.setLayoutParams(layoutParams);

        Button button = (Button) findViewById(R.id.welcome_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.startActivity(intent);
                activity.finish();
            }
        });

        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(WELCOME_VERSION_CODE_SHOWN_PREF, appVersionCode);
        editor.apply();
    }
}