List of usage examples for android.content Intent addFlags
public @NonNull Intent addFlags(@Flags int flags)
From source file:com.xiaomi.account.utils.SysHelper.java
public static Intent buildPreviousActivityIntent(Context context, Intent current, Class<? extends Activity> previous) { Intent intent = new Intent(context, previous); if (!(current == null || current.getExtras() == null)) { intent.putExtras(current.getExtras()); }/* w ww . jav a 2s . co m*/ intent.putExtra(Constants.EXTRA_FROM_BACK_NAVIGATION, true); intent.addFlags(67108864); return intent; }
From source file:edu.polyu.screamalert.SoundProcessing.java
private static void callPhone() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext); String phoneNumber = prefs.getString("phoneNumber", null); Boolean enableCall = prefs.getBoolean("enableCall", false); if (phoneNumber != null && enableCall) { if (phoneNumber.trim().length() > 0) { // Avoid empty string or white spaces in the preference field TelephonyManager phoneMgr = (TelephonyManager) thisContext .getSystemService(Context.TELEPHONY_SERVICE); if (phoneMgr.getCallState() == TelephonyManager.CALL_STATE_IDLE && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); callIntent.setData(Uri.parse("tel:" + phoneNumber)); Exchanger.thisContext.startActivity(callIntent); }/* w ww . j a v a2 s.c om*/ } } }
From source file:free.yhc.netmbuddy.utils.Utils.java
public static void resumeApp() { Intent intent = new Intent(Utils.getAppContext(), YTMPActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Utils.getAppContext().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 a v 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:com.cssweb.android.common.FairyUI.java
public static void switchToWndWithSingle(int paramInt, Context paramContext, boolean flag) { Intent localIntent = genIntent(paramInt, paramContext); localIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (localIntent != null) paramContext.startActivity(localIntent); }
From source file:com.andrewshu.android.reddit.common.Common.java
/** * /*from w ww . j av a 2 s . c om*/ * @param url * @param context * @param requireNewTask set this to true if context is not an Activity * @param bypassParser * @param useExternalBrowser */ public static void launchBrowser(Context context, String url, String threadUrl, boolean requireNewTask, boolean bypassParser, boolean useExternalBrowser, boolean saveHistory) { try { if (saveHistory) { Browser.updateVisitedHistory(context.getContentResolver(), url, true); } } catch (Exception ex) { if (Constants.LOGGING) Log.i(TAG, "Browser.updateVisitedHistory error", ex); } Uri uri = Uri.parse(url); if (!bypassParser) { if (Util.isRedditUri(uri)) { String path = uri.getPath(); Matcher matcher = COMMENT_LINK.matcher(path); if (matcher.matches()) { if (matcher.group(3) != null || matcher.group(2) != null) { CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } matcher = REDDIT_LINK.matcher(path); if (matcher.matches()) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } matcher = USER_LINK.matcher(path); if (matcher.matches()) { Intent intent = new Intent(context, ProfileActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); return; } } else if (Util.isRedditShortenedUri(uri)) { String path = uri.getPath(); if (path.equals("") || path.equals("/")) { CacheInfo.invalidateCachedSubreddit(context); Intent intent = new Intent(context, ThreadsListActivity.class); intent.setData(uri); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { // Assume it points to a thread aka CommentsList CacheInfo.invalidateCachedThread(context); Intent intent = new Intent(context, CommentsListActivity.class); intent.setData(uri); intent.putExtra(Constants.EXTRA_NUM_COMMENTS, Constants.DEFAULT_COMMENT_DOWNLOAD_LIMIT); if (requireNewTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } return; } } uri = Util.optimizeMobileUri(uri); // Some URLs should always be opened externally, if BrowserActivity doesn't support their content. if (Util.isYoutubeUri(uri) || Util.isAndroidMarketUri(uri)) useExternalBrowser = true; if (useExternalBrowser) { Intent browser = new Intent(Intent.ACTION_VIEW, uri); browser.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(browser); } else { Intent browser = new Intent(context, BrowserActivity.class); browser.setData(uri); if (threadUrl != null) browser.putExtra(Constants.EXTRA_THREAD_URL, threadUrl); if (requireNewTask) browser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(browser); } }
From source file:com.onesignal.GenerateNotification.java
private static Intent getNewBaseIntent(int notificationId) { Intent intent = new Intent(currentContext, notificationOpenedClass).putExtra("notificationId", notificationId);/*www . j a va2 s.c o m*/ if (openerIsBroadcast) return intent; return intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); }
From source file:com.andernity.launcher2.InstallShortcutReceiver.java
private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items, String name, final Intent intent, final int screen, boolean shortcutExists, final SharedPreferences sharedPrefs, int[] result) { int[] tmpCoordinates = new int[2]; if (findEmptyCell(context, items, tmpCoordinates, screen)) { if (intent != null) { if (intent.getAction() == null) { intent.setAction(Intent.ACTION_VIEW); } else if (intent.getAction().equals(Intent.ACTION_MAIN) && intent.getCategories() != null && intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); }// w w w.j av a 2 s . co m // By default, we allow for duplicate entries (located in // different places) boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); if (duplicate || !shortcutExists) { new Thread("setNewAppsThread") { public void run() { synchronized (sLock) { // If the new app is going to fall into the same page as before, // then just continue adding to the current page final int newAppsScreen = sharedPrefs.getInt(NEW_APPS_PAGE_KEY, screen); SharedPreferences.Editor editor = sharedPrefs.edit(); if (newAppsScreen == -1 || newAppsScreen == screen) { addToStringSet(sharedPrefs, editor, NEW_APPS_LIST_KEY, intent.toUri(0)); } editor.putInt(NEW_APPS_PAGE_KEY, screen); editor.commit(); } } }.start(); // Update the Launcher db LauncherApplication app = (LauncherApplication) context.getApplicationContext(); ShortcutInfo info = app.getModel().addShortcut(context, data, LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, tmpCoordinates[0], tmpCoordinates[1], true); if (info == null) { return false; } } else { result[0] = INSTALL_SHORTCUT_IS_DUPLICATE; } return true; } } else { result[0] = INSTALL_SHORTCUT_NO_SPACE; } return false; }
From source file:com.onesignal.GenerateNotification.java
private static Intent getNewBaseDeleteIntent(int notificationId) { Intent intent = new Intent(currentContext, notificationOpenedClass) .putExtra("notificationId", notificationId).putExtra("dismissed", true); if (openerIsBroadcast) return intent; return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION); }
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);// w ww . j av a2 s .c o 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(); }