Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK.

Prototype

int FLAG_ACTIVITY_NEW_TASK

To view the source code for android.content Intent FLAG_ACTIVITY_NEW_TASK.

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:android.security.cts.BrowserTest.java

/**
 * Create intents for all activities that can display the given URI.
 *///from w  w w  .  j  av a  2 s  .  c o m
private List<Intent> createAllIntents(Uri uri) {

    Intent implicit = new Intent(Intent.ACTION_VIEW);
    implicit.setData(uri);

    /* convert our implicit Intent into multiple explicit Intents */
    List<Intent> retval = new ArrayList<Intent>();
    PackageManager pm = mContext.getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(implicit, PackageManager.GET_META_DATA);
    for (ResolveInfo i : list) {
        Intent explicit = new Intent(Intent.ACTION_VIEW);
        explicit.setClassName(i.activityInfo.packageName, i.activityInfo.name);
        explicit.setData(uri);
        explicit.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        retval.add(explicit);
    }

    return retval;
}

From source file:it.uniroma2.foundme.studente.Connection.java

@Override
protected void onPostExecute(String result[]) {
    if (result[0].equalsIgnoreCase(Variables_it.NO_INTERNET)) {
        if (enProgressDialog)
            caricamento.dismiss();/*w  ww  .  j  a  v a2 s  .  co  m*/
        Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
        return;
    }
    if (enProgressDialog) {
        caricamento.dismiss();
        if (!returnMessage.equalsIgnoreCase(Variables_it.NAME)
                || result[0].equalsIgnoreCase(Variables_it.ERROR)) {
            if (!returnMessage.equalsIgnoreCase(Variables_it.SHOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.FOLLOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.UNFOLLOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.MSG)
                    && !returnMessage.equalsIgnoreCase(Variables_it.MID)) {
                Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
            }
        }
    }
    if (toDo.equalsIgnoreCase(Variables_it.GET)) {
        if (returnMessage.equalsIgnoreCase(Variables_it.SHOW))
            ShowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.FOLLOW))
            FollowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.UNFOLLOW))
            UnFollowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.MSG))
            ReadMessageActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.MID))
            ShowMsgActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.NAME) && toDo.equalsIgnoreCase(Variables_it.LOG)
            && !result[0].equalsIgnoreCase(Variables_it.ERROR)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, LoginActivity.getuser());
        SPEditor.setPass(pref, LoginActivity.getpass());
        SPEditor.setGCM(pref, result[2]);
        SPEditor.setID(pref, result[1]);
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra(Variables_it.NAME, result[0]);
        intent.putExtra(Variables_it.ID, result[1]);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    } else if (toDo.equalsIgnoreCase(Variables_it.INFOC)) {
        try {
            CourseActivity.setFields(json_data.getString(Variables_it.CFU),
                    json_data.getString(Variables_it.NAME_1), json_data.getString(Variables_it.NAME_2),
                    json_data.getInt(Variables_it.NOTIFICATION));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.CHANGEP)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setPass(pref, ChangePswActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.REGIS)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, RegistrationActivity.getmail());
        SPEditor.setPass(pref, RegistrationActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.DELACC)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.delete(pref);
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }

    else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.UNFOLLOW)) {
        try {
            UnFollowCourseActivity.getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.parse.ParsePushBroadcastReceiver.java

/**
 * Called when the push notification is opened by the user. Sends analytics info back to Parse
 * that the application was opened from this push notification. By default, this will navigate
 * to the {@link Activity} returned by {@link #getActivity(Context, Intent)}. If the push contains
 * a 'uri' parameter, an Intent is fired to view that URI with the Activity returned by
 * {@link #getActivity} in the back stack.
 *
 * @param context/*from ww w  .j  a v  a2s . c om*/
 *      The {@code Context} in which the receiver is running.
 * @param intent
 *      An {@code Intent} containing the channel and data of the current push notification.
 */
protected void onPushOpen(Context context, Intent intent) {
    // Send a Parse Analytics "push opened" event
    ParseAnalytics.trackAppOpenedInBackground(intent);

    String uriString = null;
    try {
        JSONObject pushData = new JSONObject(intent.getStringExtra(KEY_PUSH_DATA));
        uriString = pushData.optString("uri", null);
    } catch (JSONException e) {
        PLog.e(TAG, "Unexpected JSONException when receiving push data: ", e);
    }

    Class<? extends Activity> cls = getActivity(context, intent);
    Intent activityIntent;
    if (uriString != null) {
        activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
    } else {
        activityIntent = new Intent(context, cls);
    }

    activityIntent.putExtras(intent.getExtras());
    /*
      In order to remove dependency on android-support-library-v4
      The reason why we differentiate between versions instead of just using context.startActivity
      for all devices is because in API 11 the recommended conventions for app navigation using
      the back key changed.
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilderHelper.startActivities(context, cls, activityIntent);
    } else {
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(activityIntent);
    }
}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private boolean donateViaAlipay() {
    showDonateDialog();/*from w w  w . j ava 2s .c o  m*/
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(BuildConfig.DONATE_ALIPAY));
    try {
        startActivity(intent);
    } catch (Throwable t) { // NOSONAR
        hideDonateDialog();
    }
    return true;
}

From source file:com.android.prachat.gcm.MyGcmPushReceiver.java

/**
 * Showing notification with text and image
 * *//*  w w  w.j  av  a2s  .com*/
private void showNotificationMessageWithBigImage(Context context, String title, String message,
        String timeStamp, Intent intent, String imageUrl) {
    notificationUtils = new NotificationUtils(context);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationUtils.showNotificationMessage(title, message, timeStamp, intent, imageUrl);
}

From source file:de.elanev.studip.android.app.backend.net.oauth.SignInFragment.java

/**
 * Starts the next activity after prefetching.
 *///w  w  w . j  a  v a 2s  .co m
public void startMainActivity() {
    Intent intent = new Intent(getActivity(), MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

    Log.i(TAG, "Starting news Activity...");
    if (!ApiUtils.isOverApi11()) {
        getActivity().finish();
    }
}

From source file:com.android.yijiang.kzx.http.AsyncHttpResponseHandler.java

final public void sendSuccessMessage(int statusCode, Header[] headers, byte[] responseBytes) {
    String content = new String(responseBytes);
    if (content.indexOf("invalid key") != -1 || content.indexOf("token missing") != -1) {
        if (ApplicationController.mCount > 0) {
            return;
        }//from   ww  w.  ja  v a 2 s. c o m
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();
                ApplicationController.mCount++;
                MsgTools.toast(ApplicationController.getInstance(), "?,?!",
                        Toast.LENGTH_LONG);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        gotoLogin();
                    }
                }, Toast.LENGTH_SHORT);
                ApplicationController.mCount = 0;
                Looper.loop();
            }
        }).run();
    } else if (content.indexOf("need team") != -1) {
        Intent i = new Intent(ApplicationController.getInstance(), ContentFragmentActivity.class);
        i.putExtra("action", "create_team");
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        ApplicationController.getInstance().startActivity(i);
    } else {
        try {
            final boolean success = new JSONObject(content).optBoolean("success", false);
            final String message = new JSONObject(content).optString("message");
            final String data = new JSONObject(content).optString("data");
            if (!success && "null".equals(data) && StringUtils.isEmpty(message)) {
                gotoLogin();
                return;
            } else if (!success && "null".equals(data) && !StringUtils.isEmpty(message)) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        Looper.prepare();
                        MsgTools.toast(ApplicationController.getInstance(), message, Toast.LENGTH_LONG);
                        sendFinishMessage();
                        Looper.loop();
                    }
                }).run();
                return;
            }
        } catch (JSONException e) {
            e.printStackTrace();
            sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes }));
        }
        sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes }));
    }
}

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

/**
 * Installs CustomActivityOnCrash on the application using the default error activity.
 *
 * @param context Context to use for obtaining the ApplicationContext. Must not be null.
 */// ww  w .  j  a  v a2  s  .c  om
public static void install(Context context) {
    try {
        if (context == null) {
            Log.e(TAG, "Install failed: context is null!");
        } else {
            if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                Log.w(TAG,
                        "CustomActivityOnCrash will be installed, but may not be reliable in API lower than 14");
            }

            //INSTALL!
            final Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();

            if (oldHandler != null && oldHandler.getClass().getName().startsWith(CAOC_HANDLER_PACKAGE_NAME)) {
                Log.e(TAG, "You have already installed CustomActivityOnCrash, doing nothing!");
            } else {
                if (oldHandler != null
                        && !oldHandler.getClass().getName().startsWith(DEFAULT_HANDLER_PACKAGE_NAME)) {
                    Log.e(TAG,
                            "IMPORTANT WARNING! You already have an UncaughtExceptionHandler, are you sure this is correct? If you use ACRA, Crashlytics or similar libraries, you must initialize them AFTER CustomActivityOnCrash! Installing anyway, but your original handler will not be called.");
                }

                application = (Application) context.getApplicationContext();

                //We define a default exception handler that does what we want so it can be called from Crashlytics/ACRA
                Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread thread, final Throwable throwable) {
                        Log.e(TAG,
                                "App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler",
                                throwable);

                        if (hasCrashedInTheLastSeconds(application)) {
                            Log.e(TAG,
                                    "App already crashed in the last 2 seconds, not starting custom error activity because we could enter a restart loop. Are you sure that your app does not crash directly on init?",
                                    throwable);
                            if (oldHandler != null) {
                                oldHandler.uncaughtException(thread, throwable);
                                return;
                            }
                        } else {
                            setLastCrashTimestamp(application, new Date().getTime());

                            if (errorActivityClass == null) {
                                errorActivityClass = guessErrorActivityClass(application);
                            }

                            if (isStackTraceLikelyConflictive(throwable, errorActivityClass)) {
                                Log.e(TAG,
                                        "Your application class or your error activity have crashed, the custom activity will not be launched!");
                                if (oldHandler != null) {
                                    oldHandler.uncaughtException(thread, throwable);
                                    return;
                                }
                            } else if (launchErrorActivityWhenInBackground || !isInBackground) {

                                final Intent intent = new Intent(application, errorActivityClass);
                                StringWriter sw = new StringWriter();
                                PrintWriter pw = new PrintWriter(sw);
                                throwable.printStackTrace(pw);
                                String stackTraceString = sw.toString();

                                //Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent.
                                //The limit is 1MB on Android but some devices seem to have it lower.
                                //See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html
                                //And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171
                                if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) {
                                    String disclaimer = " [stack trace too large]";
                                    stackTraceString = stackTraceString.substring(0,
                                            MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer;
                                }

                                if (enableAppRestart && restartActivityClass == null) {
                                    //We can set the restartActivityClass because the app will terminate right now,
                                    //and when relaunched, will be null again by default.
                                    restartActivityClass = guessRestartActivityClass(application);
                                } else if (!enableAppRestart) {
                                    //In case someone sets the activity and then decides to not restart
                                    restartActivityClass = null;
                                }

                                String userLogString = "";
                                while (!userLogs.isEmpty()) {
                                    userLogString += userLogs.poll();
                                }

                                intent.putExtra(EXTRA_STACK_TRACE, stackTraceString);
                                intent.putExtra(EXTRA_USER_ACTION_TRACE, userLogString);
                                intent.putExtra(EXTRA_RESTART_ACTIVITY_CLASS, restartActivityClass);
                                intent.putExtra(EXTRA_SHOW_ERROR_DETAILS, showErrorDetails);
                                intent.putExtra(EXTRA_EVENT_LISTENER, eventListener);
                                intent.putExtra(EXTRA_IMAGE_DRAWABLE_ID, defaultErrorActivityDrawableId);
                                intent.setFlags(
                                        Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                if (eventListener != null) {
                                    eventListener.onLaunchErrorActivity();
                                }
                                application.startActivity(intent);
                            }
                        }
                        final Activity lastActivity = lastActivityCreated.get();
                        if (lastActivity != null) {
                            //We finish the activity, this solves a bug which causes infinite recursion.
                            //This is unsolvable in API<14, so beware!
                            //See: https://github.com/ACRA/acra/issues/42
                            lastActivity.finish();
                            lastActivityCreated.clear();
                        }
                        killCurrentProcess();
                    }
                });
                if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                    application
                            .registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
                                int currentlyStartedActivities = 0;
                                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);

                                @Override
                                public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                                    if (activity.getClass() != errorActivityClass) {
                                        // Copied from ACRA:
                                        // Ignore activityClass because we want the last
                                        // application Activity that was started so that we can
                                        // explicitly kill it off.
                                        lastActivityCreated = new WeakReference<>(activity);
                                    }
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " created\n");
                                }

                                @Override
                                public void onActivityStarted(Activity activity) {
                                    currentlyStartedActivities++;
                                    isInBackground = (currentlyStartedActivities == 0);
                                    //Do nothing
                                }

                                @Override
                                public void onActivityResumed(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " resumed\n");
                                }

                                @Override
                                public void onActivityPaused(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " paused\n");
                                }

                                @Override
                                public void onActivityStopped(Activity activity) {
                                    //Do nothing
                                    currentlyStartedActivities--;
                                    isInBackground = (currentlyStartedActivities == 0);
                                }

                                @Override
                                public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
                                    //Do nothing
                                }

                                @Override
                                public void onActivityDestroyed(Activity activity) {
                                    userLogs.add(dateFormat.format(new Date()) + " "
                                            + activity.getLocalClassName() + " destroyed\n");
                                }
                            });
                }

                Log.i(TAG, "CustomActivityOnCrash has been installed.");
            }
        }
    } catch (Throwable t) {
        Log.e(TAG,
                "An unknown error occurred while installing CustomActivityOnCrash, it may not have been properly initialized. Please report this as a bug if needed.",
                t);
    }
}

From source file:com.parse.f8.view.SignInActivity.java

public void finishActivity() {
    // Start an intent for the dispatch activity
    Intent intent = new Intent(SignInActivity.this, DispatchActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from   w  ww . j  a v a  2s. c  o m*/
}

From source file:com.adwhirl.AdWhirlLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    // Sending on an ACTION_DOWN isn't 100% correct... user could have touched
    // down and dragged out. Unlikely though.
    case MotionEvent.ACTION_DOWN:
        Log.d(AdWhirlUtil.ADWHIRL, "Intercepted ACTION_DOWN event");
        if (activeRation != null) {
            countClick();/*  w  ww  .java2 s. c o m*/

            if (activeRation.type == 9) {
                if (custom != null && custom.link != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(custom.link));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        if (activityReference == null) {
                            return false;
                        }
                        Activity activity = activityReference.get();
                        if (activity == null) {
                            return false;
                        }
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        Log.w(AdWhirlUtil.ADWHIRL, "Could not handle click to " + custom.link, e);
                    }
                } else {
                    Log.w(AdWhirlUtil.ADWHIRL, "In onInterceptTouchEvent(), but custom or custom.link is null");
                }
            }
            break;
        }
    }

    // Return false so subViews can process event normally.
    return false;
}