Example usage for android.content Intent FLAG_ACTIVITY_REORDER_TO_FRONT

List of usage examples for android.content Intent FLAG_ACTIVITY_REORDER_TO_FRONT

Introduction

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

Prototype

int FLAG_ACTIVITY_REORDER_TO_FRONT

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

Usage

From source file:com.example.sleepintrain.CheckDistance.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Intent i = new Intent(CheckDistance.this, MainActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);/* w  ww  .  j av  a2 s. c  om*/
        CheckDistance.this.finish();
    }

    return super.onKeyDown(keyCode, event);
}

From source file:org.mariotaku.twidere.activity.support.SignInActivity.java

void onSignInResult(final SignInResponse result) {
    final FragmentManager fm = getSupportFragmentManager();
    final Fragment f = fm.findFragmentByTag(FRAGMENT_TAG_SIGN_IN_PROGRESS);
    if (f instanceof DialogFragment) {
        ((DialogFragment) f).dismiss();/*from w  w  w . j a v  a2  s  .  co m*/
    }
    if (result != null) {
        if (result.succeed) {
            insertAccount(result);
            final long loggedId = result.user.getId();
            final Intent intent = new Intent(this, HomeActivity.class);
            intent.putExtra(EXTRA_REFRESH_IDS, new long[] { loggedId });
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(intent);
            finish();
        } else if (result.alreadyLoggedIn) {
            Toast.makeText(this, R.string.error_already_logged_in, Toast.LENGTH_SHORT).show();
        } else {
            ErrorLogger.exception(result.exception);
            if (result.exception instanceof AuthenticityTokenException) {
                Toast.makeText(this, R.string.wrong_api_key, Toast.LENGTH_SHORT).show();
            } else if (result.exception instanceof WrongUserPassException) {
                Toast.makeText(this, R.string.wrong_username_password, Toast.LENGTH_SHORT).show();
            } else if (result.exception instanceof AuthenticationException) {
                showErrorMessage(this, getString(R.string.action_signing_in), result.exception.getCause(),
                        true);
            } else {
                showErrorMessage(this, getString(R.string.action_signing_in), result.exception, true);
            }
        }
    }
    setSignInButton();
}

From source file:org.getlantern.firetweet.activity.support.SignInActivity.java

void onSignInResult(final SignInResponse result) {
    final FragmentManager fm = getSupportFragmentManager();
    final Fragment f = fm.findFragmentByTag(FRAGMENT_TAG_SIGN_IN_PROGRESS);
    if (f instanceof DialogFragment) {
        ((DialogFragment) f).dismissAllowingStateLoss();
    }// w  w  w  .j a  v a2  s  . c  o m
    if (result != null) {
        if (result.succeed) {
            final ContentValues values;
            switch (result.auth_type) {
            case Accounts.AUTH_TYPE_BASIC: {
                values = createAccount(result.conf, result.basic_username, result.basic_password, result.user,
                        result.color, result.api_url_format, result.no_version_suffix);
                break;
            }
            case Accounts.AUTH_TYPE_TWIP_O_MODE: {
                values = ContentValuesCreator.createAccount(result.conf, result.user, result.color,
                        result.api_url_format, result.no_version_suffix);
                break;
            }
            case Accounts.AUTH_TYPE_OAUTH:
            case Accounts.AUTH_TYPE_XAUTH: {
                values = ContentValuesCreator.createAccount(result.conf, result.access_token, result.user,
                        result.auth_type, result.color, result.api_url_format, result.same_oauth_signing_url,
                        result.no_version_suffix);
                break;
            }
            default: {
                values = null;
            }
            }
            if (values != null) {
                mResolver.insert(Accounts.CONTENT_URI, values);
            }
            final long loggedId = result.user.getId();
            final Intent intent = new Intent(this, HomeActivity.class);

            intent.putExtra(EXTRA_REFRESH_IDS, new long[] { loggedId });
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

            friendDefaultAccounts(loggedId);

            startActivity(intent);
            finish();
        } else if (result.already_logged_in) {
            Toast.makeText(this, R.string.error_already_logged_in, Toast.LENGTH_SHORT).show();
        } else {
            if (result.exception instanceof AuthenticityTokenException) {
                Toast.makeText(this, R.string.wrong_api_key, Toast.LENGTH_SHORT).show();
            } else if (result.exception instanceof WrongUserPassException) {
                Toast.makeText(this, R.string.wrong_username_password, Toast.LENGTH_SHORT).show();
            } else if (result.exception instanceof AuthenticationException) {
                showErrorMessage(this, getString(R.string.action_signing_in), result.exception.getCause(),
                        true);
            } else {
                showErrorMessage(this, getString(R.string.action_signing_in), result.exception, true);
            }
        }
    }
    setSignInButton();
}

From source file:de.spiritcroc.modular_remote.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (volumeButtonSettingsShortcutCount) {
    case 0:/*from w w w .  ja  va2s . co  m*/
    case 1:
    case 4:
    case 6:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            volumeButtonSettingsShortcutCount++;
            resetVolumeButtonSettingsShortcutHandler.postDelayed(resetVolumeButtonSettingsShortcut, 1000);
        } else {
            volumeButtonSettingsShortcutCount = 0;
        }
        break;
    case 2:
    case 3:
    case 5:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            volumeButtonSettingsShortcutCount++;
            resetVolumeButtonSettingsShortcutHandler.postDelayed(resetVolumeButtonSettingsShortcut, 1000);
        } else {
            volumeButtonSettingsShortcutCount = 0;
        }
        break;
    case 7:
        resetVolumeButtonSettingsShortcutHandler.removeCallbacks(resetVolumeButtonSettingsShortcut);
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            Toast.makeText(getApplicationContext(), R.string.toast_volume_button_settings_shortcut,
                    Toast.LENGTH_LONG).show();
            startActivity(
                    new Intent(this, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT));
        }
        volumeButtonSettingsShortcutCount = 0;
        break;
    default:
        volumeButtonSettingsShortcutCount = 0;
        break;
    }
    return pages.get(viewPager.getCurrentItem()).onKeyDown(keyCode) || super.onKeyDown(keyCode, event);
}

From source file:uk.org.ngo.squeezer.service.SqueezeService.java

/**
 * Manages the state of any ongoing notification based on the player and connection state.
 *///w  w  w . jav a2 s . com
private void updateOngoingNotification() {
    Player activePlayer = this.mActivePlayer.get();
    PlayerState activePlayerState = getActivePlayerState();

    // Update scrobble state, if either we're currently scrobbling, or we
    // were (to catch the case where we started scrobbling a song, and the
    // user went in to settings to disable scrobbling).
    if (scrobblingEnabled || scrobblingPreviouslyEnabled) {
        scrobblingPreviouslyEnabled = scrobblingEnabled;
        Scrobble.scrobbleFromPlayerState(this, activePlayerState);
    }

    // If there's no active player then kill the notification and get out.
    // TODO: Have a "There are no connected players" notification text.
    if (activePlayer == null || activePlayerState == null) {
        clearOngoingNotification();
        return;
    }

    boolean playing = activePlayerState.isPlaying();

    // If the song is not playing and the user wants notifications only when playing then
    // kill the notification and get out.
    if (!playing && !mShowNotificationWhenNotPlaying) {
        clearOngoingNotification();
        return;
    }

    // If there's no current song then kill the notification and get out.
    // TODO: Have a "There's nothing playing" notification text.
    final Song currentSong = activePlayerState.getCurrentSong();
    if (currentSong == null) {
        clearOngoingNotification();
        return;
    }

    // Compare the current state with the state when the notification was last updated.
    // If there are no changes (same song, same playing state) then there's nothing to do.
    String songName = currentSong.getName();
    String albumName = currentSong.getAlbumName();
    String artistName = currentSong.getArtist();
    Uri url = currentSong.getArtworkUrl();
    String playerName = activePlayer.getName();

    if (mNotifiedPlayerState == null) {
        mNotifiedPlayerState = new PlayerState();
    } else {
        boolean lastPlaying = mNotifiedPlayerState.isPlaying();
        Song lastNotifiedSong = mNotifiedPlayerState.getCurrentSong();

        // No change in state
        if (playing == lastPlaying && currentSong.equals(lastNotifiedSong)) {
            return;
        }
    }

    mNotifiedPlayerState.setCurrentSong(currentSong);
    mNotifiedPlayerState.setPlayStatus(activePlayerState.getPlayStatus());
    final NotificationManagerCompat nm = NotificationManagerCompat.from(this);

    PendingIntent nextPendingIntent = getPendingIntent(ACTION_NEXT_TRACK);
    PendingIntent prevPendingIntent = getPendingIntent(ACTION_PREV_TRACK);
    PendingIntent playPendingIntent = getPendingIntent(ACTION_PLAY);
    PendingIntent pausePendingIntent = getPendingIntent(ACTION_PAUSE);
    PendingIntent closePendingIntent = getPendingIntent(ACTION_CLOSE);

    Intent showNowPlaying = new Intent(this, NowPlayingActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, showNowPlaying, 0);
    Notification notification;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final Notification.Builder builder = new Notification.Builder(this);
        builder.setContentIntent(pIntent);
        builder.setSmallIcon(R.drawable.squeezer_notification);
        builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        builder.setShowWhen(false);
        builder.setContentTitle(songName);
        builder.setContentText(albumName);
        builder.setSubText(playerName);
        builder.setStyle(new Notification.MediaStyle().setShowActionsInCompactView(1, 2)
                .setMediaSession(mMediaSession.getSessionToken()));

        final MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder();
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ARTIST, artistName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_ALBUM, albumName);
        metaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, songName);
        mMediaSession.setMetadata(metaBuilder.build());

        // Don't set an ongoing notification, otherwise wearable's won't show it.
        builder.setOngoing(false);

        builder.setDeleteIntent(closePendingIntent);
        if (playing) {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_pause, "Pause", pausePendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        } else {
            builder.addAction(
                    new Notification.Action(R.drawable.ic_action_previous, "Previous", prevPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_play, "Play", playPendingIntent))
                    .addAction(new Notification.Action(R.drawable.ic_action_next, "Next", nextPendingIntent));
        }

        ImageFetcher.getInstance(this).loadImage(url,
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_height),
                new ImageWorker.ImageWorkerCallback() {
                    @Override
                    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                    public void process(Object data, @Nullable Bitmap bitmap) {
                        if (bitmap == null) {
                            bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_album_noart);
                        }

                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
                        metaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
                        mMediaSession.setMetadata(metaBuilder.build());
                        builder.setLargeIcon(bitmap);
                        nm.notify(PLAYBACKSERVICE_STATUS, builder.build());
                    }
                });
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

        builder.setOngoing(true);
        builder.setCategory(NotificationCompat.CATEGORY_SERVICE);
        builder.setSmallIcon(R.drawable.squeezer_notification);

        RemoteViews normalView = new RemoteViews(this.getPackageName(), R.layout.notification_player_normal);
        RemoteViews expandedView = new RemoteViews(this.getPackageName(),
                R.layout.notification_player_expanded);

        normalView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        expandedView.setOnClickPendingIntent(R.id.previous, prevPendingIntent);
        expandedView.setOnClickPendingIntent(R.id.next, nextPendingIntent);

        builder.setContent(normalView);

        normalView.setTextViewText(R.id.trackname, songName);
        normalView.setTextViewText(R.id.albumname, albumName);

        expandedView.setTextViewText(R.id.trackname, songName);
        expandedView.setTextViewText(R.id.albumname, albumName);
        expandedView.setTextViewText(R.id.player_name, playerName);

        if (playing) {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            normalView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_pause);
            expandedView.setOnClickPendingIntent(R.id.pause, pausePendingIntent);
        } else {
            normalView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            normalView.setOnClickPendingIntent(R.id.pause, playPendingIntent);

            expandedView.setImageViewResource(R.id.pause, R.drawable.ic_action_play);
            expandedView.setOnClickPendingIntent(R.id.pause, playPendingIntent);
        }

        builder.setContentTitle(songName);
        builder.setContentText(getString(R.string.notification_playing_text, playerName));
        builder.setContentIntent(pIntent);

        notification = builder.build();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notification.bigContentView = expandedView;
        }

        nm.notify(PLAYBACKSERVICE_STATUS, notification);

        ImageFetcher.getInstance(this).loadImage(this, url, normalView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_normal_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
        ImageFetcher.getInstance(this).loadImage(this, url, expandedView, R.id.album,
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_width),
                getResources().getDimensionPixelSize(R.dimen.album_art_icon_expanded_notification_height), nm,
                PLAYBACKSERVICE_STATUS, notification);
    }
}

From source file:com.zira.registration.BackgroundCheckActivity.java

private void forwardToNextScreen() {

    SingleTon.getInstance().setBg_address1(addressOneEditText.getText().toString());
    //   SingleTon.getInstance().setBg_address2(addressTwoEditText.getText().toString());
    SingleTon.getInstance().setBg_zipcode(zipCodeEditText.getText().toString());
    SingleTon.getInstance().setBg_drivingLicenseNumber(licenceNumberEditText.getText().toString());
    //   editor.putString("zipCode", zipCodeEditText.getText().toString());
    //   editor.putString("addressOne", addressOneEditText.getText().toString());
    //   editor.putString("licenceNumber", licenceNumberEditText.getText().toString());
    //   editor.commit();

    //SingleTon.getInstance().setBg_city(""+gettingCityPosition);

    if (licenceExpirationDate.equals("")) {
        String getdate = mProfileInfoModel.getDrivinglicenseexpirationdate();
        Date date = null;// w ww .  jav  a2 s  .  c  o  m
        try {
            date = getDateFormat.parse(getdate);
            String formattedDate = dateFormatToSend.format(date);
            SingleTon.getInstance().setBg_LicExoDate(formattedDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        /* String formattedDate = dateFormatToSend.format(date); 
        SingleTon.getInstance().setBg_LicExoDate(formattedDate);*/
    } else {
        SingleTon.getInstance().setBg_LicExoDate(licenceExpirationDate);

    }
    if (DOB.equals("")) {

        String getdatedob = mProfileInfoModel.getDateofbirth();
        Date date = null;
        try {
            date = getDateFormat.parse(getdatedob);
            String formattedDate = dateFormatToSend.format(date);
            SingleTon.getInstance().setBgDOB(formattedDate);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else {
        SingleTon.getInstance().setBgDOB(DOB);

    }
    SingleTon.getInstance().setBg_socialSecNumber(securityNumberEditText.getText().toString());
    //   editor.putString("securityNumber", securityNumberEditText.getText().toString());
    //   editor.commit();
    //finish();

    Intent intent = new Intent(BackgroundCheckActivity.this, DocumentUploadActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);

    //      startActivity(new Intent(BackgroundCheckActivity.this,DocumentUploadActivity.class));
}

From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java

public void onCreate(Bundle savedInstanceState) {
    if (debugUsbComm) {
        logString = TAG + ": onCreate";
        Log.d(TAG, logString);/* w ww  .j a va2  s .  c o m*/
        appendLog("debugUsbComm.txt", logString, false);
    }

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    camera = (SurfaceView) findViewById(R.id.smallcameraview);
    context = this.getApplicationContext();
    line1 = (TextView) findViewById(R.id.line1);
    line2 = (TextView) findViewById(R.id.line2);
    version = (TextView) findViewById(R.id.version);
    signWifi = (TextView) findViewById(R.id.advice);
    signStreaming = (TextView) findViewById(R.id.streaming);
    signInformation = (LinearLayout) findViewById(R.id.information);
    pulseAnimation = AnimationUtils.loadAnimation(this, R.anim.pulse);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);

    settings.registerOnSharedPreferenceChangeListener(this);

    camera.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder = camera.getHolder();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "com.wheelphone.remotemini.wakelock");

    httpServer = new CustomHttpServer(8080, this.getApplicationContext(), handler);

    soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 0.99f, 0.99f, 1, 0, 1);
        }
    });

    timerImg = new Timer();

    intent = new Intent(context, FrontImageActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //startActivity(intent);        

    // Query the QCAR initialization flags:
    mQCARFlags = getInitializationFlags();

    // Update the application status to start initializing application
    updateApplicationStatus(APPSTATUS_INIT_APP);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    updateRendering(size.x, size.y);

    btnStart = (Button) findViewById(R.id.btnStart);

    //Make sure that the app stays open:
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    wheelphone = new WheelphoneRobot(getApplicationContext(), getIntent());
    wheelphone.enableSpeedControl();
    wheelphone.setWheelPhoneRobotListener(this);

}

From source file:org.kegbot.app.PourInProgressActivity.java

public static Intent getStartIntent(Context context) {
    final Intent intent = new Intent(context, PourInProgressActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return intent;
}

From source file:com.zira.registration.VehicleInformationActivity.java

private void forwardToNextScreen() {

    SingleTon.getInstance().setVehicleLicencePlateNumber(licensePlateNumberEditText.getText().toString());
    //      editor.putString("licplateno", licensePlateNumberEditText.getText().toString());
    //      editor.commit();
    //finish();//  w w w .j  a v a 2  s. c o  m

    Intent intent = new Intent(VehicleInformationActivity.this, BackgroundCheckActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);

}