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.bayapps.android.robophish.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 *///  w w  w .java 2 s.c  o  m
private void showNotification(String title, String subtitle, String mediaId) {
    Intent intent = new Intent(this, MusicPlayerActivity.class);
    intent.putExtra(MusicPlayerActivity.EXTRA_START_FULLSCREEN, false);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    //TEST
    intent.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    intent.putExtra("title", title);
    intent.putExtra("subtitle", subtitle);
    intent.putExtra("showid", "__TRACKS_BY_SHOW__/" + mediaId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_allmusic_black_24dp).setContentTitle("There's a new Phish show!")
            .setContentText(title + ", " + subtitle).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(Integer.parseInt(mediaId), notificationBuilder.build());
}

From source file:com.android.settings.service.AlarmService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {//from w w w . j a va2  s .  c o  m
        startAlarmSound();
    } catch (Exception e) {
        // Do nothing
    }

    Bundle extras = intent.getExtras();
    String names = extras.getString("number");
    String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title)
            .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true)
            .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message)));

    Intent alarmDialog = new Intent();
    alarmDialog.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    alarmDialog.setClass(this, com.android.settings.service.BypassAlarm.class);
    alarmDialog.putExtra("number", names);
    alarmDialog.putExtra("norun", true);

    PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(result);
    mManager.notify(NOTI_ID, builder.build());
    return START_STICKY;
}

From source file:com.android.settings.slim.service.AlarmService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {//w ww  .j a  v  a  2s .  c  o  m
        startAlarmSound();
    } catch (Exception e) {
        // Do nothing
    }

    Bundle extras = intent.getExtras();
    String names = extras.getString("number");
    String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title)
            .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true)
            .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message)));

    Intent alarmDialog = new Intent();
    alarmDialog.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    alarmDialog.setClass(this, com.android.settings.slim.service.BypassAlarm.class);
    alarmDialog.putExtra("number", names);
    alarmDialog.putExtra("norun", true);

    PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(result);
    mManager.notify(NOTI_ID, builder.build());
    return START_STICKY;
}

From source file:com.android.settings.beanstalk.service.AlarmService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {//  ww w.j a v a 2  s  .  com
        startAlarmSound();
    } catch (Exception e) {
        // Do nothing
    }

    Bundle extras = intent.getExtras();
    String names = extras.getString("number");
    String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title);
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title)
            .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true)
            .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm)
            .setStyle(new NotificationCompat.BigTextStyle()
                    .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message)));

    Intent alarmDialog = new Intent();
    alarmDialog.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    alarmDialog.setClass(this, com.android.settings.beanstalk.service.BypassAlarm.class);
    alarmDialog.putExtra("number", names);
    alarmDialog.putExtra("norun", true);

    PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT);

    builder.setContentIntent(result);
    mManager.notify(NOTI_ID, builder.build());
    return START_STICKY;
}

From source file:com.versul.newbornswatcher.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*ww  w  . jav  a  2  s. co  m*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.eye);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.notification_large))
            .setContentTitle("Newborns Watcher").setContentText(message).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:azzaoui.sociadee.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//  w  w  w .j a va 2s  . c o  m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.pp_swag).setContentTitle("GCM Message").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}

From source file:com.alobha.challenger.business.gmc.NotificationGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param challenge GCM challenge received.
 *//*from w  w w .  j  av  a2  s.c  o m*/
private void sendNotification(Challenge challenge) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("challenge_id", challenge.id);
    intent.setAction("ShowNotification");
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.inner_logo);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.inner_logo).setLargeIcon(largeIcon)
            .setContentTitle(getString(R.string.app_name))
            .setContentText("You were challenged by " + challenge.owner.first_name).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.aluvi.android.services.push.AluviPushNotificationListenerService.java

private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}

From source file:am.project.x.utils.ContextUtils.java

/**
 * ??Intent// ww w .java  2s  .  c o m
 *
 * @param context Context
 * @return ?Intent
 */
@SuppressWarnings("unused")
public static Intent getLaunchIntent(Context context) {
    //noinspection ConstantConditions
    return context.getPackageManager().getLaunchIntentForPackage(context.getPackageName())
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}