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:com.commontime.plugin.notification.notification.AbstractActionClickActivity.java

/**
 * Launch main intent from package./*  w ww  . ja v  a 2  s  .  c  om*/
 */
public void launchApp() {
    Context context = getApplicationContext();
    String pkgName = context.getPackageName();

    Intent intent = context.getPackageManager().getLaunchIntentForPackage(pkgName);

    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    context.startActivity(intent);
}

From source file:com.tongs.user.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*  www  . ja  v  a 2  s.c  om*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            sendNotification("Send error: " + extras.toString(), 1);
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            sendNotification("Deleted messages on server: " + extras.toString(), 1);
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {

            String mode = extras.getString("collapse_key");
            Intent intent2 = null;

            if (mode.equals("change")) {
                sendNotification(" ?.", 1);
                intent2 = new Intent(this.getApplicationContext(), MainActivity.class);
                intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent2.putExtras(extras);
                startActivity(intent2);
            } else if (mode.equals("turn")) {
                sendNotification(" ?.", 1);
                intent2 = new Intent(this.getApplicationContext(), MainActivity.class);
                intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent2.putExtras(extras);
                startActivity(intent2);
            } else if (mode.equals("coupon")) {
                sendNotification("?? ?.", 2);
            } else {
                return;
            }

            Log.i(TAG, "Received: " + extras.toString());
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.nexuspad.common.activity.NPNavigateActivity.java

/**
 * Subclasses may override this method to return a custom {@link android.content.Intent}.
 *
 * @param activity//from w  w w  . j  a  v  a 2s .com
 * @return
 *         a non-null {@code Activity} {@link android.content.Intent} which will be passed
 *         to {@link #startActivity(android.content.Intent)}.
 */
protected Intent getGoBackIntent(Class<?> activity) {
    Intent intent = new Intent(this, activity);
    intent.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}

From source file:com.pr.carjoin.chat.MyFirebaseMessagingService.java

private void showNotification(Map<String, String> payLoad, String messageBody) {
    String operationCode = payLoad.get(Util.OPERATION_CODE);
    Intent intent = new Intent(this, YourTripsActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Util.OPERATION_CODE, payLoad.get(Util.OPERATION_CODE));
    intent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("CarJoin").setAutoCancel(true)
            .setContentText(messageBody).setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    switch (operationCode) {
    case "5000":
        Intent acceptedIntent = new Intent(this, NotificationReceiver.class);
        Intent declinedIntent = new Intent(this, NotificationReceiver.class);
        acceptedIntent.setAction(Constants.ACCEPTED);
        acceptedIntent.putExtra("actionCode", "5000");
        acceptedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        acceptedIntent.putExtra("valueToUpdate", Constants.ACCEPTED);

        PendingIntent acceptPendingIntent = PendingIntent.getBroadcast(this, 0, acceptedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        declinedIntent.setAction(Constants.REJECTED);
        declinedIntent.putExtra("actionCode", "5000");
        declinedIntent.putExtra(Util.REF_PATH, payLoad.get(Util.REF_PATH));
        declinedIntent.putExtra("valueToUpdate", Constants.REJECTED);

        PendingIntent declinePendingIntent = PendingIntent.getBroadcast(this, 0, declinedIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notificationBuilder.addAction(R.drawable.decline, "Decline", declinePendingIntent);
        notificationBuilder.addAction(R.drawable.accept, "Accept", acceptPendingIntent);
        notificationManager.notify(5000, notificationBuilder.build());
        break;/*  w ww .ja v  a 2  s.c o m*/
    }

}

From source file:com.none.tom.simplerssreader.service.FeedUpdateBackgroundService.java

@SuppressWarnings({ "ConstantConditions", "deprecation" })
private static void showNotification(final Context context, final List<String> payload) {
    final NotificationManager manager = context.getSystemService(NotificationManager.class);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);

        channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
        channel.setBypassDnd(false);//from  ww  w. j  ava 2s.  c  o m
        channel.enableLights(true);
        channel.setShowBadge(true);
        channel.enableVibration(true);

        manager.createNotificationChannel(channel);
    }

    final PendingIntent intent = PendingIntent.getActivity(context, 0,
            new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
            PendingIntent.FLAG_UPDATE_CURRENT);

    final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
            .setBigContentTitle(context.getString(R.string.notification_title_big));

    final int size = payload.size();

    for (int i = 0; i < size; i++) {
        style.addLine(payload.get(i));
    }

    manager.notify(ID_NOTIFICATION, new NotificationCompat.Builder(context)
            .setChannelId(NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_rss_feed_white_24dp)
            .setContentTitle(context.getString(R.string.notification_title))
            .setContentText(context.getString(R.string.notification_text)).setContentIntent(intent)
            .setStyle(style).setWhen(System.currentTimeMillis()).setAutoCancel(true).setShowWhen(true).build());
}

From source file:com.lihu.myscreenengine.Services.Impl.ScreenService.java

public boolean bringToFront(int action, String[]... args) {
    Intent intent = new Intent(MyScreenApp.getContext(), Main.class);
    try {//from   w  w w  .ja  v  a 2s  . com
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("action", action);
        for (String[] arg : args) {
            if (arg.length != 2) {
                continue;
            }
            intent.putExtra(arg[0], arg[1]);
        }
        MyScreenApp.getContext().startActivity(intent);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:io.baas.checktoe.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  w ww  . j  ava 2  s . co  m*/
private static void generateNotification(Context context, String message) {
    BaasioPayload msg = JsonUtils.parse(message, BaasioPayload.class);
    if (ObjectUtils.isEmpty(msg)) {
        return;
    }

    String alert = "";
    if (!ObjectUtils.isEmpty(msg.getAlert())) {
        alert = msg.getAlert().replace("\\r\\n", "\n");
    }

    int icon = R.drawable.ic_stat_checktoe;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // 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).setWhen(when).setSmallIcon(icon)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(alert)
            .setContentIntent(intent).setTicker(alert).setAutoCancel(true).getNotification();

    notificationManager.notify(0, notification);
}

From source file:info.zamojski.soft.towercollector.uploader.UploaderNotificationHelper.java

private PendingIntent createMainActivityResultIntent(int descriptionId) {
    Intent intent = new Intent(context, MainActivity.class);
    intent.setAction(UploaderService.SERVICE_FULL_NAME + "_NID_" + UploaderService.NOTIFICATION_ID);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(UploaderService.INTENT_KEY_RESULT_DESCRIPTION, descriptionId);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
}

From source file:com.netthreads.traffic.DetailsActivity.java

/**
 * Navigate with options./*from  w w w. j a  va2 s. c  o m*/
 *
 * @param item
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent upIntent = getParentActivityIntent();
        if (upIntent != null) {
            if (shouldUpRecreateTask(upIntent)) {
                TaskStackBuilder.create(this)
                        // Add all of this activity's parents to the back stack
                        .addNextIntentWithParentStack(upIntent)
                        // Navigate up to the closest parent
                        .startActivities();
            } else {
                upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                navigateUpTo(upIntent);
            }
        }
        return true;

    case R.id.action_settings:
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.microsoft.rightsmanagement.ui.EmailActivity.java

/**
 * Show UI./* w  w  w. j  a  va2  s.co m*/
 * 
 * @param requestCode the request code to be returned when activity completes
 * @param parentActivity the parent activity
 * @param emailActivityCompletionCallback the email activity completion callback
 */
public static void show(int requestCode, Activity parentActivity,
        CompletionCallback<String> emailActivityCompletionCallback) {
    Logger.ms(TAG, "show");
    parentActivity = validateActivityInputParameter(parentActivity);
    emailActivityCompletionCallback = validateCompletionCallbackInputParameter(emailActivityCompletionCallback);
    int requestCallbackId = emailActivityCompletionCallback.hashCode();
    sCallbackManager.putWaitingRequest(requestCallbackId, emailActivityCompletionCallback);
    Intent intent = new Intent(parentActivity, EmailActivity.class);
    intent.putExtra(REQUEST_CALLBACK_ID, requestCallbackId);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    parentActivity.startActivityForResult(intent, requestCode);
    Logger.me(TAG, "show");
}