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.ame.armymax.SettingsActivity.java

private void logout() {

    DataUser.clearAll();/*ww w  . j  av  a2 s  .co m*/

    PushService.unsubscribe(this, "channel1");

    UserHelper user = new UserHelper(this);
    user.deleteSession();

    // handle.unauth();

    Intent loginIntent = new Intent(this, LoginActivity.class);
    loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    loginIntent.putExtra("logout", true);
    startActivity(loginIntent);
    finish();

}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        Intent upIntent = new Intent(this, EpisodesActivity.class);
        upIntent.putExtra(EpisodesActivity.InitBundle.SEASON_TVDBID, mSeasonId);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so
            // create a new task with a synthesized back stack.
            TaskStackBuilder.create(this).addNextIntent(new Intent(this, ShowsActivity.class))
                    .addNextIntent(new Intent(this, OverviewActivity.class)
                            .putExtra(OverviewFragment.InitBundle.SHOW_TVDBID, mShowId))
                    .addNextIntent(upIntent).startActivities();
            finish();/*from   ww w .  j a  v  a  2 s  .  c o m*/
        } else {
            /*
             * This activity is part of the application's task, so simply
             * navigate up to the hierarchical parent activity.
             * NavUtils.navigateUpTo() does not seem to work here.
             */
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.adstrosoftware.notificationcompass.CompassService.java

/**
 * TODO/*from   w  ww  .  ja  va2  s  .c  om*/
 * 
 * @return
 */
private Notification buildNotification(int textResId, int iconResId, double azimuth) {
    Notification notification;

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP),
            PendingIntent.FLAG_UPDATE_CURRENT);

    PendingIntent stopServiceIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_STOP_SERVICE),
            PendingIntent.FLAG_UPDATE_CURRENT);

    if (!actionAdded) {
        notification = notificationBuilder.setContentTitle(getString(textResId))
                .setContentText(String.valueOf(azimuth)).setSmallIcon(iconResId).setOngoing(true)
                .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent)
                .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.stop),
                        stopServiceIntent)
                .build();

        actionAdded = true;
    } else {
        notification = notificationBuilder.setContentTitle(getString(textResId))
                .setContentText(String.valueOf(azimuth)).setSmallIcon(iconResId).setOngoing(true)
                .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).build();
    }

    return notification;
}

From source file:com.devspark.sidenavigation.meiriyiwen.MainActivity.java

private void invokeActivity3(String title, int resId) {
    Intent intent = new Intent(this, baseMenuActivity3.class);
    intent.putExtra(EXTRA_TITLE, title);
    intent.putExtra(EXTRA_RESOURCE_ID, resId);
    intent.putExtra(EXTRA_MODE, sideNavigationView.getMode() == Mode.LEFT ? 0 : 1);

    // 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.
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    startActivity(intent);//from   www  . ja  va  2s.  c  om
    // no animation of transition
    overridePendingTransition(0, 0);
}

From source file:com.parking.swipelistview.sample.adapters.MallAdapter.java

private void goToPayScreen(String mallName, long hargaParkir, String slotName, String bookingId) {
    Intent i = new Intent(ctx, InputCreditCardActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("mallName", mallName);
    i.putExtra("hargaParkir", hargaParkir);
    i.putExtra("slotName", slotName);
    i.putExtra("bookingId", bookingId);
    ctx.startActivity(i);//  w  w w . jav  a 2 s . c o m
}

From source file:com.a_login.registration.IWantWalletFragment.java

/**
 * For unrecoverable Google Wallet errors, send the user back to the checkout page to handle the
 * problem.//from  w w w  . j ava  2  s . c  om
 *
 * @param errorCode
 */
protected void handleUnrecoverableGoogleWalletError(int errorCode) {
    Intent intent = new Intent(getActivity(), SetCheckoutActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(WalletConstants.EXTRA_ERROR_CODE, errorCode);
    intent.putExtra(Constants.EXTRA_ITEM_ID, mItemId);
    startActivity(intent);
}

From source file:com.msdpe.authenticationdemo.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
 * @param shouldRedirectToLogin//from ww  w.  j a va 2 s. c  o m
 */
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, AuthenticationActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Resources res = getResources();

    if (item.getItemId() == R.id.menu_favorites_toggle) {
        onCheckedChanged(mIsStarred);/*from   w w  w .j a  va 2 s .  c o m*/

        mIsStarred = (mIsStarred ? false : true); // Toggle value
        getSherlockActivity().invalidateOptionsMenu();
        return true;
    } else if (item.getItemId() == R.id.menu_map) {
        final Intent intent = new Intent(getActivity(), MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LAT, mGeoLat);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LNG, mGeoLng);
        intent.putExtra(Const.INTENT_EXTRA_POST_ID, mIdPost);

        startActivity(intent);

        return true;
    } else if (item.getItemId() == R.id.menu_reminder) {
        parkingApp.showToastText(R.string.toast_todo_reminder, Toast.LENGTH_LONG);

        return true;
    } else if (item.getItemId() == R.id.menu_directions) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {
            /**
             * Get directions using Intents.
             */

            try {
                final Uri uriNavigation = Uri
                        .parse(String.format(Const.URI_INTENT_NAVIGATION, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriNavigation);
                startActivity(intent);

            } catch (Exception e) {
                e.printStackTrace();

                String sAddr = "";
                Location userLocation = parkingApp.getLocation();
                if (userLocation != null) {
                    sAddr = Double.toString(userLocation.getLatitude()) + ","
                            + Double.toString(userLocation.getLongitude());
                }

                final String urlGmaps = String.format(Const.URL_GMAPS_DIRECTIONS, sAddr,
                        mGeoLat + "," + mGeoLng);

                final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGmaps));
                startActivity(intent);
            }
        }
        return true;
    } else if (item.getItemId() == R.id.menu_streetview) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {

            try {
                final Uri uriStreetView = Uri
                        .parse(String.format(Const.URI_INTENT_STREETVIEW, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriStreetView);
                startActivity(intent);
            } catch (NullPointerException e) {
                e.printStackTrace();
                return false;
            } catch (Exception e) {
                parkingApp.showToastText(R.string.toast_streetview_error, Toast.LENGTH_LONG);
                e.printStackTrace();

                final Uri uriInstallStreetView = Uri.parse(Const.URI_INSTALL_STREETVIEW);
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriInstallStreetView);
                startActivity(intent);

                return false;
            }
        }
        return true;
    }

    else if (item.getItemId() == R.id.menu_share) {

        final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar();

        final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7
                : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1);
        final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY)
                + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d;

        // final int duration = parkingApp.getParkingDuration();

        final String url = String.format(res.getString(R.string.url_share_post_id), mIdPost, dayOfWeek,
                parkingHour, parkingApp.getParkingDuration());
        final String subject = String.format(res.getString(R.string.details_share_title), url);
        final String desc = String.format(res.getString(R.string.details_share_subtitle), mShareDesc);

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        // EXTRA_SUBJECT is not used to allow sharing with SMS instead of
        // MMS
        // intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, subject + Const.LINE_SEPARATOR + desc);

        startActivity(intent);
        return true;
    }

    return (activityHelper.onOptionsItemSelected(item) || super.onOptionsItemSelected(item));
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///ww  w.ja v a  2 s  .co m
private static void generateNotification(Context context, String title, String message) {

    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);
    //int icon = R.drawable.ic_stat_gcm;
    int icon = 0;
    Resources res = context.getResources();
    if (res != null) {
        //icon = res.getIdentifier(airBop_settings.mDefaultNotificationIcon, null, null);
        icon = airBop_settings.mNotificationIcon;
    }
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }
    Class intent_class = null;
    if (context != null) {
        ClassLoader class_loader = context.getClassLoader();
        if (class_loader != null) {
            try {
                if (airBop_settings.mDefaultNotificationClass != null) {
                    intent_class = Class.forName(airBop_settings.mDefaultNotificationClass);
                }
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //Log.i(TAG, "intent_class: " + intent_class);
        }
    }
    Intent notificationIntent = null;
    if (intent_class != null) {
        notificationIntent = new Intent(context, intent_class);
    } else {
        notificationIntent = new Intent(Intent.ACTION_VIEW);
    }
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.arantius.tivocommander.Utils.java

public final static boolean onOptionsItemSelected(MenuItem item, Activity srcActivity, boolean homeIsBack) {
    if (android.R.id.home == item.getItemId() && homeIsBack) {
        srcActivity.finish();/*  www.  j  a v  a 2  s . c om*/
        return true;
    }

    Class<? extends Activity> targetActivity = Utils.activityForMenuId(item.getItemId());
    if (targetActivity == null) {
        Utils.logError("Unknown menu item ID: " + Integer.toString(item.getItemId()));
        return false;
    }
    Intent intent = new Intent(srcActivity, targetActivity);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    srcActivity.startActivity(intent);
    return true;
}