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.mobicage.rogerthat.AbstractHomeActivity.java

public static void startWithLaunchInfo(final Activity activity, final String launchInfo) {
    final Intent intent = new Intent(activity, HomeActivity.class);
    intent.putExtra(INTENT_KEY_LAUNCHINFO, launchInfo);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);//  w  w w. ja v  a  2  s  . com
}

From source file:com.nps.micro.UsbService.java

/**
 * Show a notification service is testing microcontrollers.
 *//*from  ww  w .j  ava  2  s.  c  o m*/
public void showTestRunningNotification(Scenario scenario) {
    status = new Status(getText(R.string.local_service_testing).toString() + ' '
            + scenario.getSequence().toString() + ' ' + scenario.getThreadPriority().toString() + " In packet: "
            + scenario.getStreamInSize() + " Out packet: " + scenario.getStreamOutSize() + " On "
            + scenario.getDevices().length + " devices", true);
    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    Intent killIntent = new Intent();
    killIntent.setAction(KILL_ACTION);
    PendingIntent pendingIntentKill = PendingIntent.getBroadcast(getApplicationContext(), 12345, killIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setContentIntent(PendingIntent.getActivity(this, 0, intent, 0))
            .setSmallIcon(R.drawable.ic_launcher).setContentText(status.getText())
            .setContentTitle(getText(R.string.local_service_notification))
            .addAction(R.drawable.ic_launcher, getString(R.string.kill), pendingIntentKill).build();

    notificationManager.notify(NOTIFICATION, notification);
    sendStatusMessage();
}

From source file:audio.lisn.service.MediaNotificationManager.java

/**
 * Update the state based on a change on the session token. Called either when
 * we are running for the first time or when the media session owner has destroyed the session
 * (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()})
 *///from   w  w w . ja v  a2 s  .com
/*
private void updateSessionToken() {
MediaSession.Token freshToken = mService.getSessionToken();
if (mSessionToken == null || !mSessionToken.equals(freshToken)) {
    if (mController != null) {
        mController.unregisterCallback(mCb);
    }
    mSessionToken = freshToken;
    mController = new MediaController(mService, mSessionToken);
    mTransportControls = mController.getTransportControls();
    if (mStarted) {
        mController.registerCallback(mCb);
    }
}
}
*/
private PendingIntent createContentIntent() {
    Intent openUI = new Intent(mService, PlayerControllerActivity.class);
    openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java

/**
 * Callback method from {@link CalibrateListFragment.Callbacks}
 * indicating that the item with the given ID was selected.
 */// w  w w.j  av  a  2  s. com
@Override
public void onItemSelected(int id) {

    TestInfo currentTestInfo = CaddisflyApp.getApp().getCurrentTestInfo();

    fabEditCalibration.setEnabled(false);
    (new Handler()).postDelayed(new Runnable() {
        public void run() {
            fabEditCalibration.setEnabled(true);
        }
    }, FREEZE_BUTTON_DELAY_MILLIS);

    //Show edit calibration details dialog if required
    Long expiryDate = PreferencesUtil.getLong(this, currentTestInfo.getId(), R.string.calibrationExpiryDateKey);
    if (expiryDate < Calendar.getInstance().getTimeInMillis()) {
        showEditCalibrationDetailsDialog(true);
        return;
    }

    mPosition = id;
    Swatch swatch = currentTestInfo.getSwatch(mPosition);

    if (AppPreferences.useExternalCamera() || !ApiUtil.isCameraInUse(this, null)) {
        final Intent intent = new Intent(getIntent());
        intent.setClass(getBaseContext(), ColorimetryLiquidActivity.class);
        intent.putExtra("isCalibration", true);
        intent.putExtra("swatchValue", swatch.getValue());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivityForResult(intent, REQUEST_CALIBRATE);
    }
}

From source file:com.vinexs.eeb.receiver.BaseReceiverGCM.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public void onMessageTypeReceive(Context context, Intent intent) {
    notifyMgr = NotificationManagerCompat.from(context);
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    int notifyId = setting.getInt("notifyId", new Random().nextInt(65535));
    Bundle receIntent = intent.getExtras();
    try {//from   w w w  . j av  a  2s  .c o m
        if (!receIntent.containsKey("contentTitle") || !receIntent.containsKey("contentText")) {
            throw new Exception("Message don't contain necessary data.");
        }

        if (builder == null) {
            builder = new NotificationCompat.Builder(context);
            contentTitle = receIntent.getCharSequence("contentTitle");
            contentText = receIntent.getCharSequence("contentText");

            builder.setDefaults(Notification.DEFAULT_ALL).setContentTitle(contentTitle)
                    .setContentText(contentText).setSmallIcon(getMonoColorIcon())
                    .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true);
            try {
                if (Build.VERSION.SDK_INT < 14 || !receIntent.containsKey("largeIcon")) {
                    throw new Exception("Message don't contain [largeIcon] or device SDK lower than 14.");
                }
                String bigIconUrl = receIntent.getString("largeIcon");
                if (bigIconUrl == null || bigIconUrl.isEmpty()) {
                    throw new Exception("Message [largeIcon] is empty.");
                }
                HttpURLConnection connection = (HttpURLConnection) new URL(bigIconUrl).openConnection();
                connection.setDoInput(true);
                connection.connect();
                Bitmap bigIcon = BitmapFactory.decodeStream(connection.getInputStream());
                builder.setLargeIcon(bigIcon);
                // Add backgroud to wearable
                NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
                wearableExtender.setBackground(bigIcon);
                builder.extend(wearableExtender);
                // Set accent color
                int[] attrs = new int[] { R.attr.colorAccent };
                TypedArray ta = context.obtainStyledAttributes(attrs);
                String colorAccent = ta.getString(0);
                ta.recycle();
                builder.setColor(Color.parseColor(colorAccent));
            } catch (Exception e) {
                builder.setLargeIcon(
                        BitmapFactory.decodeResource(context.getResources(), getApplicationIcon()));
            }
            try {
                if (!receIntent.containsKey("ticker")) {
                    throw new Exception("Message don't contain [ticker].");
                }
                builder.setTicker(receIntent.getCharSequence("ticker"));
            } catch (Exception e) {
                builder.setTicker(receIntent.getCharSequence("contentText"));
            }
            if (Build.VERSION.SDK_INT >= 16) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
            }
        } else {
            contentText = contentText + "\n" + receIntent.getCharSequence("contentText");
            messageNum++;
            builder.setContentTitle(Utility.getAppName(context)).setContentText(contentText)
                    .setTicker(receIntent.getCharSequence("contentText")).setNumber(messageNum);
        }

        if (Build.VERSION.SDK_INT >= 16) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
        }

        Intent actionIntent = new Intent(context, getLauncherClass());
        if (receIntent.containsKey("intentAction")) {
            actionIntent.putExtra("onNewIntentAction", receIntent.getCharSequence("intentAction"));
        }
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, actionIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(contentIntent);

        notifyMgr.notify(notifyId, builder.build());
    } catch (Exception e) {
        Log.d("GoogleCloudMessaging",
                "Exception occurred while show message as notification -> " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.appdevper.mediaplayer.app.MediaNotificationManager.java

private PendingIntent createContentIntent(MediaDescriptionCompat description) {
    Intent openUI = new Intent(mService, MainActivity.class);
    openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    openUI.putExtra(MainActivity.EXTRA_START_FULLSCREEN, true);
    if (description != null) {
        openUI.putExtra(MainActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, description);
    }//from w w  w.j av  a 2s.  co  m
    return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Resources res = getResources();

    if (item.getItemId() == R.id.menu_favorites_toggle) {
        onCheckedChanged(mIsStarred);//  ww  w  .  j av  a2 s.c om

        mIsStarred = (mIsStarred ? false : true); // Toggle value
        getSherlockActivity().invalidateOptionsMenu();
        return true;
    } else if (item.getItemId() == R.id.menu_map) {
        final Intent intent = new Intent(getActivity(), MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LAT, mGeoLat);
        intent.putExtra(Const.INTENT_EXTRA_GEO_LNG, mGeoLng);
        intent.putExtra(Const.INTENT_EXTRA_POST_ID, mIdPost);

        startActivity(intent);

        return true;
    } else if (item.getItemId() == R.id.menu_reminder) {
        parkingApp.showToastText(R.string.toast_todo_reminder, Toast.LENGTH_LONG);

        return true;
    } else if (item.getItemId() == R.id.menu_directions) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {
            /**
             * Get directions using Intents.
             */

            try {
                final Uri uriNavigation = Uri
                        .parse(String.format(Const.URI_INTENT_NAVIGATION, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriNavigation);
                startActivity(intent);

            } catch (Exception e) {
                e.printStackTrace();

                String sAddr = "";
                Location userLocation = parkingApp.getLocation();
                if (userLocation != null) {
                    sAddr = Double.toString(userLocation.getLatitude()) + ","
                            + Double.toString(userLocation.getLongitude());
                }

                final String urlGmaps = String.format(Const.URL_GMAPS_DIRECTIONS, sAddr,
                        mGeoLat + "," + mGeoLng);

                final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlGmaps));
                startActivity(intent);
            }
        }
        return true;
    } else if (item.getItemId() == R.id.menu_streetview) {

        if ((Double.compare(mGeoLat, Double.MIN_VALUE) != 0)
                && (Double.compare(mGeoLng, Double.MIN_VALUE) != 0)) {

            try {
                final Uri uriStreetView = Uri
                        .parse(String.format(Const.URI_INTENT_STREETVIEW, mGeoLat, mGeoLng));
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriStreetView);
                startActivity(intent);
            } catch (NullPointerException e) {
                e.printStackTrace();
                return false;
            } catch (Exception e) {
                parkingApp.showToastText(R.string.toast_streetview_error, Toast.LENGTH_LONG);
                e.printStackTrace();

                final Uri uriInstallStreetView = Uri.parse(Const.URI_INSTALL_STREETVIEW);
                final Intent intent = new Intent(Intent.ACTION_VIEW, uriInstallStreetView);
                startActivity(intent);

                return false;
            }
        }
        return true;
    }

    else if (item.getItemId() == R.id.menu_share) {

        final GregorianCalendar parkingCalendar = parkingApp.getParkingCalendar();

        final int dayOfWeek = (parkingCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY ? 7
                : parkingCalendar.get(Calendar.DAY_OF_WEEK) - 1);
        final double parkingHour = parkingCalendar.get(Calendar.HOUR_OF_DAY)
                + Math.round(parkingCalendar.get(Calendar.MINUTE) / 0.6) / 100.00d;

        // final int duration = parkingApp.getParkingDuration();

        final String url = String.format(res.getString(R.string.url_share_post_id), mIdPost, dayOfWeek,
                parkingHour, parkingApp.getParkingDuration());
        final String subject = String.format(res.getString(R.string.details_share_title), url);
        final String desc = String.format(res.getString(R.string.details_share_subtitle), mShareDesc);

        final Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("text/plain");
        // EXTRA_SUBJECT is not used to allow sharing with SMS instead of
        // MMS
        // intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, subject + Const.LINE_SEPARATOR + desc);

        startActivity(intent);
        return true;
    }

    return (activityHelper.onOptionsItemSelected(item) || super.onOptionsItemSelected(item));
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from  w  w w.  ja  v a2s.c o m*/
private static void generateNotification(Context context, String title, String message) {

    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);
    //int icon = R.drawable.ic_stat_gcm;
    int icon = 0;
    Resources res = context.getResources();
    if (res != null) {
        //icon = res.getIdentifier(airBop_settings.mDefaultNotificationIcon, null, null);
        icon = airBop_settings.mNotificationIcon;
    }
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }
    Class intent_class = null;
    if (context != null) {
        ClassLoader class_loader = context.getClassLoader();
        if (class_loader != null) {
            try {
                if (airBop_settings.mDefaultNotificationClass != null) {
                    intent_class = Class.forName(airBop_settings.mDefaultNotificationClass);
                }
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //Log.i(TAG, "intent_class: " + intent_class);
        }
    }
    Intent notificationIntent = null;
    if (intent_class != null) {
        notificationIntent = new Intent(context, intent_class);
    } else {
        notificationIntent = new Intent(Intent.ACTION_VIEW);
    }
    // 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).setContentTitle(title)
            .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.mattprecious.notisync.service.SecondaryService.java

private Notification buildRunningNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setPriority(NotificationCompat.PRIORITY_MIN);
    builder.setSmallIcon(R.drawable.ic_stat_logo);
    builder.setContentTitle(getString(R.string.app_name));

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    builder.setContentIntent(pendingIntent);

    if (!bluetoothAdapter.isEnabled()) {
        builder.setContentText(getString(R.string.noti_bt_not_enabled));

        PendingIntent bluetoothIntent = PendingIntent.getActivity(this, 0,
                new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), 0);
        builder.addAction(R.drawable.ic_action_bluetooth, getString(R.string.noti_action_enable_bt),
                bluetoothIntent);/*from  w  w w  .  ja v  a  2s.  c o m*/
    } else if (connectedDeviceName == null) {
        builder.setContentText(getString(R.string.noti_not_connected));
    } else {
        builder.setContentText(getString(R.string.noti_connected_to, connectedDeviceName));
    }

    return builder.build();
}

From source file:org.ado.minesync.gui.notification.MineSyncNotification.java

private PendingIntent getMainPendingIntent() {
    Intent intent = new Intent(service, MineSyncMainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(service, 0, intent, 0);
}