List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP
int FLAG_ACTIVITY_SINGLE_TOP
To view the source code for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.
Click Source Link
From source file:at.alladin.rmbt.android.test.RMBTLoopService.java
private void setFinishedNotification() { Intent notificationIntent = new Intent(getApplicationContext(), RMBTMainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent openAppIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); final Resources res = getResources(); final Notification notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_icon_loop) .setContentTitle(res.getText(R.string.loop_notification_finished_title)) .setTicker(res.getText(R.string.loop_notification_finished_ticker)).setContentIntent(openAppIntent) .build();// w ww. j av a 2s .c o m //notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(NotificationIDs.LOOP_ACTIVE, notification); }
From source file:info.curtbinder.reefangel.service.NotificationService.java
private Intent getStatusActivity() { Intent si = new Intent(this, StatusActivity.class); si.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); si.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); si.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); return si;/*from ww w .ja v a 2 s .co m*/ }
From source file:com.nxp.nfc_demo.activities.MainActivity.java
public void setNfcForeground() { // Create a generic PendingIntent that will be delivered to this // activity. The NFC stack will fill // in the intent with the details of the discovered tag before // delivering it to this activity. mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(getApplicationContext(), getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); }
From source file:com.digi.android.wva.WvaApplication.java
/** * Display a status bar notification about the alarm. * //from w w w . ja va 2 s .c om * @param alarmName name of alarm * @param data VehicleData with data that triggered the alarm */ void showAlarmNotification(String alarmName, VehicleData data) { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new Builder(this); Intent activityIntent = new Intent(this, DashboardActivity.class); activityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Get alarm sound out of preferences SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); String ringtoneStr = sp.getString("pref_key_alarm_tone", null); // Make items passed in to builder methods Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Uri ringtone = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr); PendingIntent pend = PendingIntent.getActivity(this, 0, activityIntent, 0); // Build the notification and show it builder.setLargeIcon(largeIcon).setSmallIcon(R.drawable.notif_small) .setContentTitle("WVA Alarm: " + alarmName).setContentText("Value: " + data.value) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setSound(ringtone).setContentIntent(pend) .setTicker("WVA Alarm: " + alarmName); nm.notify(ALARM_NOTIF_ID, builder.build()); }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
/** * Raises a notification with a biggest earthquake with each sync * * @param notifyValues data with the biggest recent earthquake *//* w w w .j ava 2 s . c om*/ private void sendNotification(ContentValues notifyValues) { Context context = getContext(); if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) { //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) { Intent intent = new Intent(context, DetailActivity.class); double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE); double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE); LatLng latLng = new LatLng(latitude, longitude); String distance = context.getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(context))); String magnitude = context.getString(R.string.earthquake_magnitude, notifyValues.getAsDouble(EarthquakeColumns.MAG)); String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME)); double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH); intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG)); intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE)); intent.putExtra(Feature.DATE, date); intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL)); intent.putExtra(Feature.LATLNG, latLng); intent.putExtra(Feature.DISTANCE, distance); intent.putExtra(Feature.DEPTH, depth); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher); builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true) .setContentTitle(context.getString(R.string.earthquake_statistics_largest)) .setContentText(context.getString(R.string.earthquake_magnitude, notifyValues.get(EarthquakeColumns.MAG))) .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp) .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n" + distance + "\n" + date)) .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true); NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context); managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build()); //refreshing last sync boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit(); } } }
From source file:biz.bokhorst.bpt.BPTService.java
private Notification getNotification(String text) { // Build intent Intent toLaunch = new Intent(this, BackPackTrack.class); toLaunch.setAction("android.intent.action.MAIN"); toLaunch.addCategory("android.intent.category.LAUNCHER"); toLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Build pending intent PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, PendingIntent.FLAG_UPDATE_CURRENT); // Build result intent update Intent resultIntentUpdate = new Intent(this, BPTService.class); resultIntentUpdate.setAction("Update"); // Build pending intent waypoint PendingIntent pendingIntentUpdate = PendingIntent.getService(this, 2, resultIntentUpdate, PendingIntent.FLAG_UPDATE_CURRENT); // Build result intent waypoint Intent resultIntentWaypoint = new Intent(this, BPTService.class); resultIntentWaypoint.setAction("Waypoint"); // Build pending intent waypoint PendingIntent pendingIntentWaypoint = PendingIntent.getService(this, 2, resultIntentWaypoint, PendingIntent.FLAG_UPDATE_CURRENT); // Build notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); notificationBuilder.setSmallIcon(R.drawable.icon); notificationBuilder.setContentTitle(getString(R.string.app_name)); notificationBuilder.setContentText(text); notificationBuilder.setContentIntent(intentBack); notificationBuilder.setWhen(System.currentTimeMillis()); notificationBuilder.setAutoCancel(true); notificationBuilder.addAction(android.R.drawable.ic_menu_mylocation, getString(R.string.Update), pendingIntentUpdate);/*from www .j a va2 s. com*/ notificationBuilder.addAction(android.R.drawable.ic_menu_add, getString(R.string.Waypoint), pendingIntentWaypoint); Notification notification = notificationBuilder.build(); return notification; }
From source file:com.wolkabout.hexiwear.service.BluetoothService.java
protected Notification getNotification(final BluetoothDevice device) { final boolean connectionEstablished = isConnected && bluetoothGatt != null && bluetoothGatt.getDevice() != null; final String text = connectionEstablished ? "Device is connected to " + hexiwearDevice.getWolkName() : "Device is not connected."; final int icon = connectionEstablished ? R.drawable.ic_bluetooth_connected_white_48dp : R.drawable.ic_bluetooth_searching_white_48dp; final Intent readingsActivityIntent = ReadingsActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_SINGLE_TOP) .device(device).get();/*from w ww. ja v a 2s .c o m*/ final Intent mainActivityIntent = MainActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_SINGLE_TOP).get(); final Intent launchActivity = connectionEstablished ? readingsActivityIntent : mainActivityIntent; final PendingIntent pendingIntentMain = PendingIntent.getActivity(this, 71, launchActivity, PendingIntent.FLAG_UPDATE_CURRENT); final Intent stopIntent = new Intent(STOP); final PendingIntent pendingStopIntent = PendingIntent.getBroadcast(this, 0, stopIntent, 0); return new NotificationCompat.Builder(this).setSmallIcon(icon) .setContentTitle(getResources().getString(R.string.app_name)).setContentIntent(pendingIntentMain) .setLights(Color.GREEN, 100, 5000) .addAction(R.drawable.ic_cloud_off_black_24dp, "Stop", pendingStopIntent).setContentText(text) .build(); }
From source file:com.tencent.wstt.gt.activity.GTLogFragment.java
private void openLog(final String filename) { if (filename == null) { return;/*from w w w. j a v a2 s . c o m*/ } currentlyOpenLog = filename; Intent intent = new Intent(getActivity(), GTLogSearchActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("openFileName", filename); startActivity(intent); }
From source file:com.bonsai.btcreceive.WalletService.java
private void showStatusNotification() { // In this sample, we'll use the same text for the ticker and // the expanded notification CharSequence started_txt = getText(R.string.wallet_service_started); CharSequence info_txt = getText(R.string.wallet_service_info); Notification note = new Notification(R.drawable.ic_stat_notify, started_txt, System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); // Set the info for the views that show in the notification panel. note.setLatestEventInfo(this, getText(R.string.wallet_service_label), info_txt, contentIntent); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(NOTIFICATION, note); }
From source file:com.google.android.apps.forscience.whistlepunk.review.RunReviewFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == android.R.id.home) { Intent upIntent = NavUtils.getParentActivityIntent(getActivity()); if (mExperimentRun != null) { upIntent.putExtra(ExperimentDetailsFragment.ARG_EXPERIMENT_ID, mExperimentRun.getExperimentId()); upIntent.putExtra(ExperimentDetailsFragment.ARG_CREATE_TASK, getArguments().getBoolean(ARG_CREATE_TASK, false)); upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), getView().getRootView().findViewById(R.id.app_bar_layout), mStartLabelId); getActivity().startActivity(upIntent, options.toBundle()); } else if (getActivity() != null) { // This is a weird error situation: we didn't load the experiment run at all. // In this case, just finish. getActivity().onBackPressed(); return true; }// w ww . ja v a2s . co m return true; } else if (id == R.id.action_graph_options) { mGraphOptionsController.launchOptionsDialog(mScalarDisplayOptions, new NewOptionsStorage.SnackbarFailureListener(getView())); } else if (id == R.id.action_export) { getDataController().getExperimentRun(mStartLabelId, new LoggingConsumer<ExperimentRun>(TAG, "retrieve argument") { @Override public void success(final ExperimentRun run) { exportRun(run); } }); } else if (id == R.id.action_run_review_crop) { // TODO: Add crop functionality. AccessibilityUtils.makeSnackbar(getView(), getActivity().getResources().getString(R.string.action_not_available), Snackbar.LENGTH_SHORT) .show(); } else if (id == R.id.action_run_review_add_note) { if (mExperimentRun != null) { launchLabelAdd(new GoosciLabelValue.LabelValue(), LABEL_TYPE_UNDECIDED, Math.max(mRunReviewOverlay.getTimestamp(), mExperimentRun.getFirstTimestamp())); } } else if (id == R.id.action_run_review_delete) { if (mExperimentRun != null) { deleteThisRun(); } } else if (id == R.id.action_run_review_archive) { if (mExperimentRun != null) { setArchived(true); } } else if (id == R.id.action_run_review_unarchive) { if (mExperimentRun != null) { setArchived(false); } } else if (id == R.id.action_run_review_edit) { UpdateRunActivity.launch(getActivity(), mStartLabelId); } else if (id == R.id.action_enable_auto_zoom) { if (mExperimentRun != null) { setAutoZoomEnabled(true); } } else if (id == R.id.action_disable_auto_zoom) { if (mExperimentRun != null) { setAutoZoomEnabled(false); } } else if (id == R.id.action_run_review_audio_settings) { launchAudioSettings(); } return super.onOptionsItemSelected(item); }