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.afrolkin.samplepushclient.GCMIntentService.java

private static void generateNotification(Context context, String message) {
    int icon = R.mipmap.ic_announcement_black_48dp;
    long when = System.currentTimeMillis();
    String title = context.getString(R.string.app_name);
    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, "Push Message", when);
    notification.sound = soundUri;/* w ww.j  a  v a 2 s .  c om*/

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message", message);
    // 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,
            PendingIntent.FLAG_CANCEL_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:kr.ac.kookmin.cs.firstcoin.order.data.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    // Log.e("log_gcm_msg", msg);
    Map<String, String> msgMap = new HashMap<String, String>();
    String dataPair[] = msg.split(",");

    for (int i = 0; i < dataPair.length; i++) {
        String data = dataPair[i];
        String[] keyValue = data.split("=");
        keyValue[0] = keyValue[0].trim();
        msgMap.put(keyValue[0], keyValue[1]);
        Log.e("log_gcm_map", keyValue[0] + "," + keyValue[1]);
    }/*from   w  ww.jav a2s.  co m*/

    String title = msgMap.get("title");
    String message = msgMap.get("message");

    Intent intent = new Intent(GcmIntentService.this, StartActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis() / 1000,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setVibrate(new long[] { 200, 1000, 200, 1000 }) // manifest 
            .setSmallIcon(R.drawable.ic_launcher_order_app_logo).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setTicker(title)
            .setContentText(message).setContentIntent(contentIntent).setDefaults(0)
            .setLights(Color.GREEN, 1000, 100).setAutoCancel(true);

    // // 
    PushWakeLock.acquireCpuWakeLock(this);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    PushWakeLock.releaseCpuLock();

}

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

/**
 * Show UI/*from ww  w.j  ava  2s  . com*/
 * 
 * @param requestCode
 * @param parentActivity
 * @param consents - consents collection containing serverurlconsent or documentTrackingConsent
 * @param emailActivityCompletionCallback
 */
public static void show(int requestCode, Activity parentActivity, Collection<Consent> consents,
        CompletionCallback<Collection<Consent>> consentActivityCompletionCallback) {
    Logger.ms(TAG, "show");
    parentActivity = validateActivityInputParameter(parentActivity);
    consentActivityCompletionCallback = validateCompletionCallbackInputParameter(
            consentActivityCompletionCallback);
    consents = validateConsentInputParamter(consents);
    ConsentModel consentModel = new ConsentModel(consents);
    int requestCallbackId = consentActivityCompletionCallback.hashCode();
    sCallbackManager.putWaitingRequest(requestCallbackId, consentActivityCompletionCallback, consents);
    Intent intent = new Intent(parentActivity, ConsentActivity.class);
    intent.putExtra(REQUEST_CALLBACK_ID, requestCallbackId);
    intent.putExtra(REQUEST_CONSENT_MODEL, consentModel);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    parentActivity.startActivityForResult(intent, requestCode);
    Logger.me(TAG, "show");
}

From source file:com.cellasoft.univrapp.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*  w  w w  . j a  v  a  2  s  . c  om*/
private void displayNotification(Context context, String message) {
    if (!Settings.isEnabledNotificationUnivrApp()) {
        return;
    }

    LOGI(TAG, "displayNotification: " + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    long[] vibraPattern = { 0, 500, 250, 500 };
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(
            Config.GCM_NOTIFICATION_ID,
            new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, ChannelListActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))
                    .setAutoCancel(true).setVibrate(vibraPattern).setDefaults(Notification.DEFAULT_SOUND)
                    .getNotification());
}

From source file:org.adictolinux.mfcclone.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();//from  w  w w  .j  av  a 2s  .  c om
    menuTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer
    // opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, menuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mAdapter = NfcAdapter.getDefaultAdapter(this);
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    mFilters = new IntentFilter[] { new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED) };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { MifareClassic.class.getName() } };

    // Escondemos el teclado hasta que el user toca una entrada de texto
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    if (savedInstanceState == null) {
        replaceFragment(new ForceKeysFragment(), 0);
    }
}

From source file:com.preguardia.app.notification.MyGcmListenerService.java

private void showConsultationClosedNotification(String title, String message, String consultationId) {
    // Prepare intent which is triggered if the notification is selected
    Intent intent = new Intent(this, ConsultationDetailsActivity.class);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_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_stat_logo).setContentTitle(title).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(5, notificationBuilder.build());
}

From source file:com.codebutler.farebot.activity.AddKeyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_key);
    getWindow().setLayout(WRAP_CONTENT, MATCH_PARENT);

    findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w w. j  a v  a  2  s . c  o  m*/
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final String keyType = ((RadioButton) findViewById(R.id.is_key_a)).isChecked()
                    ? ClassicSectorKey.TYPE_KEYA
                    : ClassicSectorKey.TYPE_KEYB;

            new BetterAsyncTask<Void>(AddKeyActivity.this, true, false) {
                @Override
                protected Void doInBackground() throws Exception {
                    ClassicCardKeys keys = ClassicCardKeys.fromDump(keyType, mKeyData);

                    ContentValues values = new ContentValues();
                    values.put(KeysTableColumns.CARD_ID, mTagId);
                    values.put(KeysTableColumns.CARD_TYPE, mCardType);
                    values.put(KeysTableColumns.KEY_DATA, keys.toJSON().toString());

                    getContentResolver().insert(CardKeyProvider.CONTENT_URI, values);

                    return null;
                }

                @Override
                protected void onResult(Void unused) {
                    Intent intent = new Intent(AddKeyActivity.this, KeysActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();
                }
            }.execute();
        }
    });

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Utils.checkNfcEnabled(this, mNfcAdapter);

    Intent intent = getIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)
            && getIntent().getData() != null) {
        // Request permission for storage first
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                    STORAGE_PERMISSION_CALLBACK);
        } else {
            // Just read the key file
            readKeyFile();
        }

    } else {
        finish();
    }
}

From source file:butter.droid.base.torrent.TorrentService.java

public void startForeground() {
    if (Foreground.get().isForeground())
        return;//from   ww  w.j  a  v  a  2  s  .  com
    if (mCurrentActivityClass == null)
        return;

    Intent notificationIntent = new Intent(this, mCurrentActivityClass);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    Intent stopIntent = new Intent();
    stopIntent.setAction(TorrentBroadcastReceiver.STOP);
    PendingIntent pendingStopIntent = PendingIntent.getBroadcast(this, TorrentBroadcastReceiver.REQUEST_CODE,
            stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(
            R.drawable.abc_ic_clear_mtrl_alpha, getString(R.string.stop), pendingStopIntent).build();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notif_logo)
            .setContentTitle(getString(R.string.app_name) + " - " + getString(R.string.running))
            .setContentText(getString(R.string.tap_to_resume)).setOngoing(true).setOnlyAlertOnce(true)
            .setPriority(Notification.PRIORITY_LOW).setContentIntent(pendingIntent).addAction(stopAction)
            .setCategory(NotificationCompat.CATEGORY_SERVICE);

    if (mStreamStatus != null && mIsReady) {
        String downloadSpeed;
        DecimalFormat df = new DecimalFormat("#############0.00");
        if (mStreamStatus.downloadSpeed / 1024 < 1000) {
            downloadSpeed = df.format(mStreamStatus.downloadSpeed / 1024) + " KB/s";
        } else {
            downloadSpeed = df.format(mStreamStatus.downloadSpeed / (1024 * 1024)) + " MB/s";
        }
        String progress = df.format(mStreamStatus.progress);
        builder.setContentText(progress + "%, " + downloadSpeed);
    }

    Notification notification = builder.build();

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

    notifManager.notify(NOTIFICATION_ID, notification);
    startForeground(NOTIFICATION_ID, notification);

    if (mUpdateTimer == null) {
        mUpdateTimer = new Timer();
        mUpdateTimer.scheduleAtFixedRate(new UpdateTask(), 5000, 5000);
    }
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.gcm.MyGCMIntentService.java

public static void generateNotification(Context context) {
    String message = (String) context.getText(R.string.notification_body);
    String titleSingle = (String) context.getText(R.string.notification_title_single);
    String titlePlural = (String) context.getText(R.string.notification_title_plural);
    String titleFrom = (String) context.getText(R.string.notification_title_from);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher_light)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
            .setVibrate(new long[] { 0, 1000, 0, 0, 0 }) // {delay, vibrate, sleep, vibrate, sleep}
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    if (newMessagesFromDifferentUsers) {
        mBuilder.setContentTitle(/*from w  w  w  .  j  a v a  2s. c om*/
                newMessages + " " + context.getText(R.string.notification_new_messages) + " " + titlePlural)
                .setContentText(message);
    } else {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        if (newMessages == 1) {
            mBuilder.setContentTitle(
                    newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName)
                    .setContentText(newMessageContent.get(0));
            inboxStyle.setBigContentTitle(
                    newMessages + " " + titleSingle + " " + titleFrom + " " + newMessagePartyName);
            inboxStyle.addLine(newMessageContent.get(0));
        } else {
            mBuilder.setContentTitle(
                    newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName)
                    .setContentText(message);
            inboxStyle.setBigContentTitle(
                    newMessages + " " + titlePlural + " " + titleFrom + " " + newMessagePartyName);

            for (int i = 0; i < newMessageContent.size(); i++) {
                inboxStyle.addLine(newMessageContent.get(i));
            }
            if (newMessages > 2) {
                inboxStyle.addLine((String) context.getText(R.string.notification_dots) + (newMessages - 2)
                        + " " + context.getText(R.string.notification_more_messages)
                        + context.getText(R.string.notification_dots));
            }
        }

        mBuilder.setStyle(inboxStyle);
    }

    int myPackage = context.getResources().getIdentifier(NOTIFICATION_PACKAGE, ConstantKeys.STRING,
            context.getPackageName());

    int myClass = context.getResources().getIdentifier(NOTIFICATION_CLASS, ConstantKeys.STRING,
            context.getPackageName());

    ComponentName c = new ComponentName(context.getString(myPackage), context.getString(myClass));
    Intent notificationIntent = new Intent();
    notificationIntent.setComponent(c);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.putExtra(ConstantKeys.NOTIFICATION, newMessageTimelineId);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(intent);

    NotificationManager mNotifyMgr = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    mNotifyMgr.notify(0, mBuilder.build());
}

From source file:com.scooter1556.sms.android.activity.HomeActivity.java

private void startFullScreenActivityIfNeeded(Intent intent) {
    if (intent != null && intent.getBooleanExtra(EXTRA_START_FULLSCREEN, false)) {
        Intent fullScreenIntent = new Intent(this, FullScreenPlayerActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .putExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION,
                        intent.getParcelableExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION));

        startActivity(fullScreenIntent);
    }//  w  w  w.  j a  va  2  s  . co m
}