Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:com.qbcps.sifterclient.SifterReader.java

private void deleteKeys() {
    File keyFile = getFileStreamPath(KEY_FILE);
    if (keyFile.exists()) {
        //noinspection ResultOfMethodCallIgnored
        keyFile.delete();/*  ww  w.j  a va2  s  .co  m*/
        mAllProjects = null;
        mDomain = null;
        mAccessKey = null;
        try {
            mLoginError = mSifterHelper.onMissingToken();
        } catch (Exception e) {
            e.printStackTrace();
            mSifterHelper.onException(e.toString());
            return;
        }
        setListAdapter(null);
        onContentChanged();
    }
    // launch the login activity
    loginKeys(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}

From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingLanguageActivity.java

public void setLocale(String lang) {
    Resources res = this.getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    android.content.res.Configuration conf = res.getConfiguration();
    conf.locale = new Locale(lang.toLowerCase());
    res.updateConfiguration(conf, dm);/*w w w.  j  a v  a2 s  . com*/
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    /*
    FLAG_ACTIVITY_CLEAR_TOP
    If set, and the activity being launched is already running in the current task,
    then instead of launching a new instance of that activity, all of the other
    activities on top of it will be closed and this Intent will be delivered to
    the (now on top) old activity as a new Intent.
     */
    startActivity(intent);
}

From source file:com.microsoft.firstapp.AuthService.java

/**
 * Handles logging the user out including: -deleting cookies so their login
 * with a provider won't be cached in the web view -removing the userdata
 * from the shared preferences -setting the current user object on the
 * client to logged out -optionally redirects to the login page if requested
 * //  www .j a  v  a  2s  . com
 * @param shouldRedirectToLogin
 */
public void logout(boolean shouldRedirectToLogin) {
    // Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    // Clear the user id and token from the shared preferences
    SharedPreferences settings = mContext.getSharedPreferences("UserData", 0);
    SharedPreferences.Editor preferencesEditor = settings.edit();
    preferencesEditor.clear();
    preferencesEditor.commit();
    // Clear the user and return to the auth activity
    mClient.logout();
    // Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, LogInActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:com.qubittech.feelknit.app.MainActivity.java

private Intent GetIntent(Class cls) {
    Intent intent = new Intent(MainActivity.this, cls);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("EXIT", true);
    return intent;
}

From source file:kr.co.bettersoft.checkmileage.activities.GCMIntentService.java

/**
 * generateNotification//from   www .j  ava2s  . c om
 * Issues a notification to inform the user that server has sent a message.
 * @param context
 * @param message
 * @return
 */
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when); // sdf
    String title = context.getString(R.string.app_name);
    String mileageUpdateStr = context.getString(R.string.mileage_noti);
    Intent notificationIntent;
    /*
     * MILEAGE :  ? ??  ? ???.
     * MARKETING : ?? ?    ?.
     * Check Mileage     ?. : test ..
     * 
     * <string name="gcm_new_msgkkk"> </string>
     */
    String new_msg = " ";

    if (message.equals(new_msg)) {
        Log.d(TAG, "new msg - test");
        notificationIntent = new Intent(context, DummyActivity.class);
        //            notificationIntent.putExtra("RunMode", "TEST");                  // ?? ? . ?? .. ?   ..
        notificationIntent.putExtra("RunMode", "MILEAGE"); //

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);

        //        }else if(message.contains("MILEAGE")){
        //        }else if(message.contains(mileageUpdateStr)){         // ?? ?. ()
    } else if (message.equals(mileageUpdateStr)) { // ?? ?. ().
        Log.d(TAG, "update mileage");
        MyMileagePageActivity.searched = false;
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ?..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MILEAGE");

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else if (message.equals("MARKETING")) {
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", "New Event");
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else { //  ?.
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", message);

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
}

From source file:com.beem.project.beem.ui.wizard.AccountConfigureFragment.java

/**
 * Callback called when the Manual configuration button is selected.
 *
 *///from ww w .  j  a v a 2  s.  c om
public void onManualConfigurationSelected() {
    Intent i = new Intent(getActivity(), Settings.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(i, MANUAL_CONFIGURATION_CODE);
}

From source file:org.openhab.habdroid.ui.OpenHABRoomSettingActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(TAG, "onActivityResult " + String.valueOf(requestCode) + " " + String.valueOf(resultCode));
    if (resultCode == -1) {
        // Right now only PreferencesActivity returns -1
        // Restart app after preferences
        Log.i(TAG, "Restarting");
        // Get launch intent for application
        Intent restartIntent = getBaseContext().getPackageManager()
                .getLaunchIntentForPackage(getBaseContext().getPackageName());
        restartIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // Finish current activity
        finish();//from   ww w.  jav a2s  .  co m
        // Start launch activity
        startActivity(restartIntent);
    }
}

From source file:com.battlelancer.seriesguide.ui.OverviewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        Intent upIntent = new Intent(this, ShowsActivity.class);
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(upIntent);/*  ww w . j  a v  a2  s .c o m*/
        return true;
    } else if (itemId == R.id.menu_overview_search) {
        launchSearch();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

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();//ww  w. j  av  a2  s .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.romanenco.gitt.BrowserActivity.java

/**
 * When pull from origin there are several case.
 * 1. We are in TAG (detached head): will inform user to
 * checkout a branch first.//from  w ww.java2 s .  c om
 * 2. Authentication required: ask for password (no passwd save).
 * 3. Anonymous user: just poll.
 */
private void pullFromOrigin() {
    if (current.getUserName() == null) {
        //no authentication required
        current.setState(Repo.State.Busy);
        DAO dao = new DAO(BrowserActivity.this);
        dao.open(true);
        dao.update(current);
        dao.close();
        Intent pull = new Intent(this, GitService.class);
        pull.putExtra(GitService.COMMAND, GitService.Command.Pull);
        pull.putExtra(GitService.REPO, current);
        startService(pull);
        Intent main = new Intent(this, MainActivity.class);
        main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(main);
    } else {
        String req = getString(R.string.passwd_request, current.getUserName());
        final EditText passwd = new EditText(this);
        passwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        AlertDialog dlg = new AlertDialog.Builder(this).setMessage(req)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        String password = passwd.getText().toString();
                        if (TextUtils.isEmpty(password)) {
                            pullFromOrigin();
                        } else {
                            current.setState(Repo.State.Busy);
                            DAO dao = new DAO(BrowserActivity.this);
                            dao.open(true);
                            dao.update(current);
                            dao.close();
                            Intent pull = new Intent(BrowserActivity.this, GitService.class);
                            pull.putExtra(GitService.COMMAND, GitService.Command.Pull);
                            pull.putExtra(GitService.REPO, current);
                            pull.putExtra(GitService.AUTH_PASSWD, password);
                            startService(pull);
                            Intent main = new Intent(BrowserActivity.this, MainActivity.class);
                            main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(main);
                        }
                    }
                }).setNegativeButton(getString(android.R.string.cancel), null).create();
        dlg.setCanceledOnTouchOutside(false);
        dlg.setView(passwd);
        dlg.show();
    }

}