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.perm.DoomPlay.PlayingService.java

private Notification createOldNotif() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    Intent intentActivity;/*from  w  ww .  j ava 2s . co m*/

    if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) {
        intentActivity = new Intent(FullPlaybackActivity.actionReturnFull);
        intentActivity.setClass(this, FullPlaybackActivity.class);
        intentActivity.putExtra(FileSystemActivity.keyMusic, audios);
    } else {
        intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios);
    }
    intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    builder.setContentIntent(
            PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_UPDATE_CURRENT))
            .setOngoing(true)
            .setSmallIcon(isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play);

    Audio audio = audios.get(indexCurrentTrack);

    builder.setContentTitle(audio.getTitle());
    builder.setContentText(audio.getArtist());

    Bitmap cover = AlbumArtGetter.getBitmapFromStore(audio.getAid(), this);
    if (cover == null) {
        Bitmap tempBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fallback_cover);
        builder.setLargeIcon(tempBitmap);
        tempBitmap.recycle();
    } else {
        builder.setLargeIcon(cover);
        cover.recycle();
    }

    return builder.build();
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

@SuppressWarnings("deprecation")
public void setServiceForeground(Context mContext) {
    final int myID = 9999;

    // The intent to launch when the user clicks the expanded notification
    Intent mIntent = new Intent(mContext, BackgroundActivity.class);
    mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0, mIntent, 0);

    // This constructor is deprecated. Use Notification.Builder instead
    Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name),
            System.currentTimeMillis());

    // This method is deprecated. Use Notification.Builder instead.
    mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification),
            pendIntent);// w w  w . ja  v a  2  s.  c  o  m

    mNotification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(myID, mNotification);
}

From source file:io.selendroid.server.ServerInstrumentation.java

public void resumeActivity() {
    Activity activity = activitiesReporter.getBackgroundActivity();
    Log.d("TAG", "got background activity");
    if (activity == null) {
        SelendroidLogger.error("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;/*from  w  w w.  j  a va  2 s  .  c  o m*/
    }
    // start now the new activity
    Log.d("TAG", "background activity is not null");
    Intent intent = new Intent(getTargetContext(), activity.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Log.d("TAG", "created intent and got target context");
    getTargetContext().startActivity(intent);
    Log.d("TAG", "got target context and started activity");
    activitiesReporter.setBackgroundActivity(null);
}

From source file:com.android.contacts.common.list.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap;//  ww  w .j a v  a2 s.co m
    Uri phoneUri;
    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call);
    } else {
        phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp);
    }

    Intent shortcutIntent = new Intent(shortcutAction, phoneUri);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }
    if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.call_by_shortcut, displayName));
    } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.sms_by_shortcut, displayName));
    }

    mListener.onShortcutIntentCreated(uri, intent);
}

From source file:com.aegiswallet.actions.MainActivity.java

private void checkIfAppInitiated() {
    if (!prefs.getBoolean(Constants.APP_INIT_COMPLETE, false)) {
        Intent openMainActivity = new Intent(this, InitAppAction.class);
        openMainActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(openMainActivity);
    }// w ww .j a va2  s . c  om
}

From source file:com.appolis.putaway.AcPutAwayDetails.java

/**
 * Process event for views//from w  ww . ja va2s.c  o  m
 */
@Override
public void onClick(View v) {
    Intent intent;
    switch (v.getId()) {
    case R.id.imgHome:
        Utilities.hideKeyboard(this);
        intent = new Intent(AcPutAwayDetails.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(intent, GlobalParams.LOGINSCREEN_TO_MAINSCREEN);
        break;

    case R.id.img_main_menu_scan_barcode:
        intent = new Intent(this, CaptureBarcodeCamera.class);
        startActivityForResult(intent, GlobalParams.AC_PUT_AWAY_LEVEL_TWO);
        break;

    case R.id.btnCancel:
        Utilities.hideKeyboard(this);
        finish();
        break;

    case R.id.btnOK:
        try {
            prepareJsonForm();
            PostItemAsyncTask postItemAsyncTask = new PostItemAsyncTask();
            postItemAsyncTask.execute();
        } catch (JSONException e) {

        } catch (Exception e) {

        }

        break;

    default:
        break;
    }
}

From source file:com.mytwitter.activity.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.action_timeline) {

        Intent i = new Intent(HomeActivity.this, MyTweetsActivity.class);
        startActivity(i);//from ww  w .j  a  v  a  2s . co  m
        overridePendingTransition(R.anim.slide_activity_in_right, R.anim.slide_activity_out_right);
        return true;

    } else if (id == R.id.action_retweet) {

        Intent i = new Intent(HomeActivity.this, MyReTweetsActivity.class);
        startActivity(i);
        overridePendingTransition(R.anim.slide_activity_in_right, R.anim.slide_activity_out_right);
        return true;

    } else if (id == R.id.action_profile) {

        Intent i = new Intent(HomeActivity.this, ProfileActivity.class);
        startActivity(i);
        overridePendingTransition(R.anim.slide_activity_in_right, R.anim.slide_activity_out_right);
        return true;

    } else if (id == R.id.action_lic) {

        displayLicensesDialogFragment();
        return true;

    }
    /*else if (id == R.id.action_tweet) {
            
     TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
     Intent intent = new ComposerActivity.Builder(HomeActivity.this)
            .session(session)
            .createIntent();
    startActivity(intent);
    return true;
    }*/
    else if (id == R.id.action_logout) {

        PreferencesHelper.setLoginCheck(false);
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
        Intent i = new Intent(HomeActivity.this, LoginActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);
        finish();
        overridePendingTransition(R.anim.activity_slide_in_left, R.anim.activity_slide_out_left);
        return true;
    }
    if (id == R.id.action_aboutus) {

        Intent i = new Intent(HomeActivity.this, AboutUsActivity.class);
        startActivity(i);
        overridePendingTransition(R.anim.slide_activity_in_right, R.anim.slide_activity_out_right);
        return true;

    }

    return super.onOptionsItemSelected(item);
}

From source file:eu.operando.proxy.OperandoProxyStatus.java

private void reloadActivity() {
    finish();/*from w w w  .j  a v a  2  s.  c  o m*/
    Intent intent = new Intent(this, MainProxyActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:com.appolis.move.AcMoveDetails.java

/**
 * Process event for views//from   w  w w. j av  a2 s  . co m
 */
@Override
public void onClick(View v) {
    Intent intent;
    switch (v.getId()) {
    case R.id.imgHome:
        Utilities.hideKeyboard(this);
        intent = new Intent(AcMoveDetails.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivityForResult(intent, GlobalParams.LOGINSCREEN_TO_MAINSCREEN);
        break;

    case R.id.img_main_menu_scan_barcode:
        intent = new Intent(this, CaptureBarcodeCamera.class);
        startActivityForResult(intent, GlobalParams.AC_MOVE_LEVEL_TWO);
        break;

    case R.id.btnCancel:
        finish();
        break;

    case R.id.btnOK:
        try {
            PostItemAsyncTask postItemAsyncTask = new PostItemAsyncTask();
            postItemAsyncTask.execute();
        } catch (Exception e) {

        }

        break;

    default:
        break;
    }
}

From source file:cis350.blanket.IntentIntegrator.java

/**
 * Create an scan intent with the specified options.
 *
 * @return the intent//from  ww w  .  j av  a2  s  . c  o m
 */
public Intent createScanIntent() {
    Intent intentScan = new Intent(activity, getCaptureActivity());
    intentScan.setAction("com.google.zxing.client.android.SCAN");

    // check which types of codes to scan for
    if (desiredBarcodeFormats != null) {
        // set the desired barcode types
        StringBuilder joinedByComma = new StringBuilder();
        for (String format : desiredBarcodeFormats) {
            if (joinedByComma.length() > 0) {
                joinedByComma.append(',');
            }
            joinedByComma.append(format);
        }
        intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
    }

    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    attachMoreExtras(intentScan);
    return intentScan;
}