Example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_SINGLE_TOP

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

Click Source Link

Document

If set, the activity will not be launched if it is already running at the top of the history stack.

Usage

From source file:kashmirr.social.service.NotificationService.java

private void sendGeneralNotification(Context context, String uniqueId, String title, String contentText,
        @Nullable Bundle extra) {//from w ww  .  j av  a  2  s.  c  om

    NotificationManager notificationManagerCompat = (NotificationManager) context
            .getSystemService(NOTIFICATION_SERVICE);

    android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(
            context);
    builder.setSmallIcon(R.drawable.ic_bell_ring_outline_white_24dp);
    builder.setAutoCancel(true);

    builder.setContentTitle(title);
    builder.setContentText(contentText);
    builder.setGroup(GROUP_KEY_MESSAGES);
    builder.setDefaults(android.app.Notification.DEFAULT_ALL);
    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));

    Intent requestsViewIntent = new Intent(context,
            mSharedHelper.isLoggedIn() ? HomeActivity.class : SplashScreen.class);
    if (extra != null) {
        requestsViewIntent.putExtra(NOTIFICATION_BUNDLE_EXTRA_KEY, extra);
    }
    requestsViewIntent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    requestsViewIntent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent requestsViewPending = PendingIntent.getActivity(context, Integer.valueOf(uniqueId),
            requestsViewIntent, 0);
    builder.setContentIntent(requestsViewPending);

    builder.setShowWhen(true);
    android.app.Notification notification = builder.build();
    notificationManagerCompat.notify(Integer.valueOf(uniqueId), notification);
}

From source file:com.hoho.android.usbserial.examples.SerialConsoleActivity.java

/**
 * Starts the activity, using the supplied driver instance.
 *
 * @param context/*from  w w w  .ja  v  a2 s .com*/
 */
static void show(Context context, UsbSerialPort port) {
    sPort = port;
    final Intent intent = new Intent(context, SerialConsoleActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
    context.startActivity(intent);
}

From source file:de.persoapp.android.core.adapter.MainViewFragment.java

protected void excludeFromRecentAppList(Activity activity) {
    // a dirty hack to exclude this activity from the recent app list after the process finished
    // since it runs in singleInstance mode onNewIntent will be called
    final Intent intent = new Intent(activity, activity.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    startActivity(intent);//from  www.j a v  a 2s  .  com
}

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

private void reloadActivity() {
    finish();//from w w w  . j av a 2  s  . co 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.fsck.k9.activity.Accounts.java

public static void listAccounts(Context context) {
    Intent intent = new Intent(context, Accounts.class);

    if (Build.VERSION.SDK_INT >= 11) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    } else {//from ww w  . j  ava2  s . c o m
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    }

    intent.putExtra(EXTRA_STARTUP, false);
    context.startActivity(intent);
}

From source file:com.trellmor.berrytubechat.ChatActivity.java

private void loadPreferences() {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {/*from  w  w w  .j a  va2s.  co m*/
        mScrollback = Integer.parseInt(settings.getString(MainActivity.KEY_SCROLLBACK, "100"));
    } catch (NumberFormatException e) {
        mScrollback = 100;
    }

    if (mScrollback <= 0)
        mScrollback = 100;

    if (mBinder != null)
        mBinder.getService().setChatMsgBufferSize(mScrollback);

    try {
        mFlair = Integer.parseInt(settings.getString(MainActivity.KEY_FLAIR, "0"));
    } catch (NumberFormatException e) {
        mFlair = 0;
    }

    if (settings.getBoolean(MainActivity.KEY_SQUEE, false)) {
        mNotification = new NotificationCompat.Builder(this);
        mNotification.setSmallIcon(R.drawable.ic_stat_notify_chat);
        mNotification.setLights(0xFF0000FF, 100, 2000);
        mNotification.setAutoCancel(true);

        Intent intent = new Intent(this, ChatActivity.class);
        intent.putExtra(MainActivity.KEY_USERNAME, mUsername);
        intent.putExtra(MainActivity.KEY_PASSWORD, mPassword);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);

        mNotification.setContentIntent(
                PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        String squee = settings.getString(MainActivity.KEY_SQUEE_RINGTONE, "");
        if (!"".equals(squee)) {
            mNotification.setSound(Uri.parse(squee), AudioManager.STREAM_NOTIFICATION);
        }
        if (settings.getBoolean(MainActivity.KEY_SQUEE_VIBRATE, false)) {
            mNotification.setVibrate(new long[] { 0, 100 });
        }
    } else {
        mNotification = null;
    }

    boolean showVideo = settings.getBoolean(MainActivity.KEY_VIDEO, false);
    if (showVideo != mShowVideo) {
        // If the value has changed, act on it
        if (showVideo) {
            if (!mFirstPrefLoad) {
                Toast.makeText(this, R.string.toast_video_enabled, Toast.LENGTH_LONG).show();
            }
        } else {
            mBinder.getService().disableVideoMessages();
            setTextVideoVisible(false);
        }
    }
    mShowVideo = showVideo;

    mShowDrinkCount = settings.getBoolean(MainActivity.KEY_DRINKCOUNT, true);
    mPopupPoll = settings.getBoolean(MainActivity.KEY_POPUP_POLL, false);
    updateDrinkCount();

    mFirstPrefLoad = false;
}

From source file:im.vector.receiver.VectorUniversalLinkReceiver.java

/**
 * Start the universal link management when the login process is done.
 * If there is no active activity, launch the home activity
 *
 * @param aContext the context.//from   ww w. j a v  a 2s .c om
 */
private void manageGroupDetailsActivity(final Context aContext) {
    Log.d(LOG_TAG, "## manageMemberDetailsActivity() : open the group" + mParameters.get(ULINK_GROUP_ID_KEY));

    final Activity currentActivity = VectorApp.getCurrentActivity();

    if (null != currentActivity) {
        Intent startRoomInfoIntent = new Intent(currentActivity, VectorGroupDetailsActivity.class);
        startRoomInfoIntent.putExtra(VectorGroupDetailsActivity.EXTRA_GROUP_ID,
                mParameters.get(ULINK_GROUP_ID_KEY));
        startRoomInfoIntent.putExtra(VectorGroupDetailsActivity.EXTRA_MATRIX_ID,
                mSession.getCredentials().userId);
        currentActivity.startActivity(startRoomInfoIntent);
    } else {
        // clear the activity stack to home activity
        Intent intent = new Intent(aContext, VectorHomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(VectorHomeActivity.EXTRA_GROUP_ID, mParameters.get(ULINK_GROUP_ID_KEY));
        aContext.startActivity(intent);
    }
}

From source file:com.linkbubble.ui.BubbleDraggable.java

public void doAnimateToContentView(MainController controller, boolean startDelay) {
    Intent intentActivity = new Intent(getContext(), BubbleFlowActivity.class);
    intentActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    getContext().startActivity(intentActivity);
    doAnimateToContentView(true, startDelay, controller);
}

From source file:com.nextgis.ngm_clink_monitoring.services.FoclReportService.java

protected static Notification getNotification(Context context, int notificationType, String errorMsg) {
    Intent intent = new Intent(context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
            .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setOngoing(false);/*from www.ja va 2 s  .  c  o m*/

    switch (notificationType) {
    case NOTIFICATION_START:
        builder.setProgress(0, 0, true).setSmallIcon(R.drawable.ic_sync_started)
                .setTicker(context.getString(R.string.report_started))
                .setContentTitle(context.getString(R.string.report))
                .setContentText(context.getString(R.string.report_progress));
        break;

    case NOTIFICATION_FINISH:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_finished)
                .setTicker(context.getString(R.string.report_finished))
                .setContentTitle(context.getString(R.string.report))
                .setContentText(context.getString(R.string.report_finished));
        break;

    case NOTIFICATION_CANCELED:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_error)
                .setTicker(context.getString(R.string.report_canceled))
                .setContentTitle(context.getString(R.string.report))
                .setContentText(context.getString(R.string.report_canceled));
        break;

    case NOTIFICATION_ERROR:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_error)
                .setTicker(context.getString(R.string.report_error))
                .setContentTitle(context.getString(R.string.report_error)).setContentText(errorMsg);
        break;
    }

    return builder.build();
}

From source file:by.zatta.pilight.connection.ConnectionService.java

private static void makeNotification(NotificationType type, String message) {
    Intent main;//  w ww.  j  a v  a2  s . c  o  m
    Intent kill;
    PendingIntent sentBroadcast;
    PendingIntent startMainActivity;
    PendingIntent killService;

    String myDate = java.text.DateFormat.getTimeInstance().format(Calendar.getInstance().getTime());

    //Log.v(TAG, "setting notification: " + type.name() + " while current = " + mCurrentNotif.name());
    if (type != mCurrentNotif) {
        //Log.v(TAG, "setting NEW notification: " + type.name());
        sendMessageToUI(MSG_SET_STATUS, type.name());
        switch (type) {
        case DESTROYED:
            builder = new Notification.Builder(ctx);
            builder.setSmallIcon(R.drawable.eye_black).setLargeIcon(bigPic(R.drawable.eye_black))
                    .setContentTitle(aCtx.getString(R.string.app_name)).setContentText(message);
            mCurrentNotif = NotificationType.DESTROYED;
            break;
        case CONNECTING:
            kill = new Intent("pilight-kill-service");
            killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT);

            builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name))
                    .setContentText(message).setDeleteIntent(killService).setSmallIcon(R.drawable.eye_trans)
                    .setLargeIcon(bigPic(R.drawable.eye_trans));
            mCurrentNotif = NotificationType.CONNECTING;
            break;
        case CONNECTED:
            main = new Intent(ctx, MainActivity.class);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

            builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name))
                    .setContentText(message + "\n" + myDate).setContentIntent(startMainActivity)
                    .setSmallIcon(R.drawable.eye_white).setLargeIcon(bigPic(R.drawable.eye_white));
            mCurrentNotif = NotificationType.CONNECTED;
            break;
        case FAILED:
            main = new Intent("pilight-reconnect");
            sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
            kill = new Intent("pilight-kill-service");
            killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT);

            builder = new Notification.Builder(ctx).setContentTitle("pilight")
                    .setContentText(aCtx.getString(R.string.noti_failed)).setDeleteIntent(killService)
                    .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast)
                    .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans));
            mCurrentNotif = NotificationType.FAILED;
            break;
        case LOST_CONNECTION:
            main = new Intent("pilight-reconnect");
            sentBroadcast = PendingIntent.getBroadcast(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
            kill = new Intent("pilight-kill-service");
            killService = PendingIntent.getBroadcast(ctx, 0, kill, PendingIntent.FLAG_UPDATE_CURRENT);

            builder = new Notification.Builder(ctx).setContentTitle(aCtx.getString(R.string.app_name))
                    .setContentText(message + "\n" + myDate).setDeleteIntent(killService)
                    .addAction(R.drawable.action_refresh, aCtx.getString(R.string.noti_retry), sentBroadcast)
                    .setSmallIcon(R.drawable.eye_trans).setLargeIcon(bigPic(R.drawable.eye_trans));
            mCurrentNotif = NotificationType.LOST_CONNECTION;
            break;
        case UPDATE:
            main = new Intent(ctx, MainActivity.class);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startMainActivity = PendingIntent.getActivity(ctx, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);
            String[] title = message.split("\n");
            message = message.replace(title[0] + "\n", "");
            builder = new Notification.Builder(ctx).setContentTitle(title[0]).setContentText(message)
                    .setStyle(new Notification.BigTextStyle().bigText(message))
                    .setContentIntent(startMainActivity).setSmallIcon(R.drawable.eye_white)
                    .setLargeIcon(bigPic(R.drawable.eye_white));
            mCurrentNotif = NotificationType.UPDATE;
            break;
        default:
            break;
        }
    } else {
        if (message != null) {
            if (message.contains("Stamp")) {
                String[] title = message.split("\n");
                message = message.replace(title[0] + "\n", "");
                builder.setContentTitle(title[0]).setStyle(new Notification.BigTextStyle().bigText(message));
                builder.setContentText(message);
            } else {
                builder.setContentTitle(myDate).setStyle(new Notification.BigTextStyle().bigText(message));
                builder.setContentText(message);
            }
        }
    }
    mNotMan.notify(35, builder.build());
}