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:de.lazyheroproductions.campuscardreader.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // get an instance of the local broadcast manager to receive messages which are send inside the application
    LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
            new IntentFilter(CardReaderIntentService.CAMPUS_CARD_INTENT));
    creditTextView = (TextView) findViewById(R.id.credit);
    transactionTextView = (TextView) findViewById(R.id.last_transaction);

    if (BuildConfig.DEBUG) {
        Log.i(this.getClass().getName(), "received intent on create");
    }/*from w  ww.java2 s  . c  o  m*/
    startNfcIntentService(getIntent());

    // intercept all NFC related Intents and redirect them to this activity while this activity is activ and on the front
    // this is called the "foreground dispatch"
    mAdapter = NfcAdapter.getDefaultAdapter(this);
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    IntentFilter nfcTech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
    mFilters = new IntentFilter[] { nfcTech };
    mTechLists = new String[][] { new String[] { IsoDep.class.getName() }, { NfcA.class.getName() } };

    //adview related stuff
    //        adView = (AdView) this.findViewById(R.id.adView);
    setUpAdview();
}

From source file:io.selendroid.ServerInstrumentation.java

public void startActivity(Class activity) {
    if (activity == null) {
        SelendroidLogger.log("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;/*from   w  ww  .j  av a  2s  .c  om*/
    }
    finishAllActivities();
    // start now the new activity
    Intent intent = new Intent(getTargetContext(), activity);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    Activity a = startActivitySync(intent);
}

From source file:jp.co.ipublishing.esnavi.helpers.android.AppActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int id = item.getItemId();

    if (id == android.R.id.home) {
        final Intent intent = new Intent(this, MapActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);//from w  w  w . j  av  a  2  s .c o  m
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.nextgis.mobile.datasource.SyncAdapter.java

public void sendNotification(Context context, String notificationType, String message) {
    if (!PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SettingsConstants.KEY_PREF_SHOW_SYNC,
            false))/*  w  ww  .  java  2s  .co m*/
        return;

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_action_sync).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent).setAutoCancel(true).setOngoing(false);

    Bitmap largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_sync, context.getResources());
    switch (notificationType) {
    case SYNC_START:
        largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_next_dark, context.getResources());
        builder.setProgress(0, 0, true).setTicker(context.getString(com.nextgis.maplib.R.string.sync_started))
                .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization))
                .setContentText(context.getString(com.nextgis.maplib.R.string.sync_progress));
        break;

    case SYNC_FINISH:
        largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_apply_dark, context.getResources());
        builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_finished))
                .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization))
                .setContentText(context.getString(com.nextgis.maplib.R.string.sync_finished));
        break;

    case SYNC_CANCELED:
        largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_cancel_dark, context.getResources());
        builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_canceled))
                .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization))
                .setContentText(context.getString(com.nextgis.maplib.R.string.sync_canceled));
        break;

    case SYNC_CHANGES:
        largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_action_warning_dark, context.getResources());
        builder.setProgress(0, 0, false).setTicker(context.getString(com.nextgis.maplib.R.string.sync_error))
                .setContentTitle(context.getString(com.nextgis.maplib.R.string.synchronization))
                .setContentText(message);
        break;
    }

    builder.setLargeIcon(largeIcon);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}

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

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {//w  w w.  ja va  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.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.maryplasez.spicemeapp.MyFirebaseMessagingService.java

/**
 * Called when message is received./*from  w  w w.j  a v a 2 s. com*/
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    // [START_EXCLUDE]
    // There are two types of messages data messages and notification messages. Data messages are handled
    // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
    // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
    // is in the foreground. When the app is in the background an automatically generated notification is displayed.
    // When the user taps on the notification they are returned to the app. Messages containing both notification
    // and data payloads are treated as notification messages. The Firebase console always sends notification
    // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
    // [END_EXCLUDE]

    // TODO(developer): Handle FCM messages here.
    // Not getting messages here? See why this may be: https://goo.gl/39bRNJ
    Log.d(TAG, "From: " + remoteMessage.getFrom());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
        Log.d(TAG, "Message data payload: " + remoteMessage.getData());
    }

    // Check if message contains a notification payload.
    if (remoteMessage.getNotification() != null) {
        Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
    }

    Intent intent = new Intent(getBaseContext(), ChatActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);
    // Also if you intend on generating your own notifications as a result of a received FCM
    // message, here is where that should be initiated. See sendNotification method below.
}

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

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {//from  w ww . j a v a 2  s .  c  om
        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:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java

/**
 * Posts notification about new sms ticket.
 *
 * @param c context to post notification
 * @param t new ticket//  www  .ja  v a2 s . c  om
 */
public static void notifyTicket(Context c, Ticket t, boolean keepNotification) {
    String text;
    String ticker;
    int smallIcon;
    int largeIcon;
    int status;
    switch (TicketsAdapter.getValidityStatus(t.getStatus(), t.getValidTo())) {
    case TicketProvider.Tickets.STATUS_VALID:
    case TicketProvider.Tickets.STATUS_VALID_EXPIRING:
        text = c.getString(R.string.notif_valid_text, FormatUtil.formatDateTimeDifference(t.getValidTo()));
        ticker = c.getString(R.string.notif_valid_ticker);
        smallIcon = R.drawable.notification_small_ready;
        largeIcon = R.drawable.notification_big_ready;
        status = TicketProvider.Tickets.STATUS_VALID_EXPIRING;
        break;
    case TicketProvider.Tickets.STATUS_EXPIRING:
    case TicketProvider.Tickets.STATUS_EXPIRING_EXPIRED:
        text = c.getString(R.string.notif_expiring_text, FormatUtil.formatTime(t.getValidTo()));
        ticker = c.getString(R.string.notif_expiring_ticker);
        smallIcon = R.drawable.notification_small_warning;
        largeIcon = R.drawable.notification_big_warning;
        status = TicketProvider.Tickets.STATUS_EXPIRING_EXPIRED;
        break;
    case TicketProvider.Tickets.STATUS_EXPIRED:
        text = c.getString(R.string.notif_expired_text, FormatUtil.formatTime(t.getValidTo()));
        ticker = c.getString(R.string.notif_expired_ticker);
        smallIcon = R.drawable.notification_small_expired;
        largeIcon = R.drawable.notification_big_expired;
        status = TicketProvider.Tickets.STATUS_EXPIRED;
        break;
    default:
        return;
    }

    Intent intent = new Intent(c, WearableService.class);
    intent.setAction("sent_notification_to_wear");
    intent.putExtra("ticket", t);
    intent.putExtra("status", status);
    c.startService(intent);

    Intent i = new Intent(c, MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra(MainActivity.EXTRA_TICKET_ID, t.getId());
    PendingIntent openIntent = PendingIntent.getActivity(c, t.getNotificationId(), i,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Intent i2 = new Intent(c, MainActivity.class);
    i2.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i2.putExtra(MainActivity.EXTRA_TICKET_ID, t.getId());
    i2.putExtra(MainActivity.EXTRA_SHOW_SMS, true);
    PendingIntent showSmsIntent = PendingIntent.getActivity(c, t.getNotificationId() + 1000, i2,
            PendingIntent.FLAG_CANCEL_CURRENT);
    List<Action> actions = new ArrayList<Action>();
    actions.add(new Action(R.drawable.notification_show_sms, R.string.notif_show_sms, showSmsIntent));
    List<String> rows = new ArrayList<String>();
    rows.add(text);
    rows.add(c.getString(R.string.tickets_valid_from) + ": " + FormatUtil.formatDateTime(t.getValidFrom()));
    rows.add(c.getString(R.string.tickets_code) + ": " + t.getHash());
    fireNotification(c, t.getNotificationId(), openIntent, c.getString(R.string.application_name), text, rows,
            t.getCity(), ticker, smallIcon, largeIcon, actions, keepNotification);
}

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

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    try {/*from  www .  java 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.dvdprime.mobile.android.gcm.command.CommentCommand.java

private void displayNotification(Context context, String message) {
    LOGI(TAG, "Displaying notification: " + message);
    Gcm gcm = GsonUtil.fromJson(message, Gcm.class);
    SystemUtil.launcherBroadcast(DpApp.class, gcm.getCount());
    String targetUrl = null;//from   ww w  .  ja v  a  2 s  .  c  o m
    try {
        targetUrl = URLDecoder.decode(gcm.getTargetUrl(), Config.UTF8);
    } catch (UnsupportedEncodingException e) {
    }
    if (PrefUtil.getInstance().getBoolean(PrefKeys.NOTIFICATION_COMMENT, true) && targetUrl != null) {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
                new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                        .setSmallIcon(R.drawable.ic_launcher).setTicker(gcm.getMessage())
                        .setContentTitle(gcm.getMessage()).setContentText(gcm.getTitle())
                        .setContentIntent(PendingIntent.getActivity(context, 0,
                                new Intent(context, DocumentViewActivity.class)
                                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                                                | Intent.FLAG_ACTIVITY_SINGLE_TOP)
                                        .setData(Uri.parse(targetUrl))
                                        .putExtra("targetKey", gcm.getTargetKey()),
                                0))
                        .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true).build());
    }
}