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:com.airbop.library.simple.AirBopGCMIntentService.java
private static void generateNotification(Context context, String title, String message, String url, String large_icon) {/*from w ww .ja va 2 s .c o m*/ //int icon = R.drawable.ic_stat_gcm; AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); int 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; } Intent notificationIntent = null; if ((url == null) || (url.equals(""))) { //just bring up the app if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { notificationIntent = new Intent(context, Class.forName(airBop_settings.mDefaultNotificationClass)); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); //notificationIntent = new Intent(Intent.ACTION_VIEW); } } } } else { //Launch the URL notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse(url)); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); } PendingIntent intent = null; // set intent so it does not start a new activity if (notificationIntent != null) { notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); } Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)); if (intent != null) { notificationBuilder.setContentIntent(intent); } if (icon != 0) { notificationBuilder.setSmallIcon(icon); } Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
/** * Start the universal link management when the login process is done. * If there is no active activity, launch the home activity * * @param aContext the context./* w w w . j a v a 2 s . co m*/ */ private void manageRoomOnActivity(final Context aContext) { final Activity currentActivity = VectorApp.getCurrentActivity(); if (null != currentActivity) { currentActivity.runOnUiThread(new Runnable() { @Override public void run() { manageRoom(aContext); } }); } else { // clear the activity stack to home activity Intent intent = new Intent(aContext, VectorHomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(VectorHomeActivity.EXTRA_WAITING_VIEW_STATUS, VectorHomeActivity.WAITING_VIEW_START); aContext.startActivity(intent); try { final Timer wakeup = new Timer(); wakeup.schedule(new TimerTask() { @Override public void run() { wakeup.cancel(); manageRoomOnActivity(aContext); } }, 200); } catch (Throwable throwable) { Log.e(LOG_TAG, "## manageRoomOnActivity timer creation failed " + throwable.getMessage()); manageRoomOnActivity(aContext); } } }
From source file:com.racoon.ampdroid.Mp3PlayerService.java
private void setNotifiction() { RemoteViews notificationView = new RemoteViews(this.getPackageName(), R.layout.player_notification); notificationView.setTextViewText(R.id.notificationSongArtist, getArtist()); notificationView.setTextViewText(R.id.notificationSongTitle, getCurrentTitle()); /* 1. Setup Notification Builder */ Notification.Builder builder = new Notification.Builder(this); /* 2. Configure Notification Alarm */ builder.setSmallIcon(R.drawable.ic_stat_notify).setAutoCancel(true).setWhen(System.currentTimeMillis()) .setTicker(getCurrentTitle()); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent notifIntent = PendingIntent.getActivity(this, 0, intent, 0); builder.setContentIntent(notifIntent); builder.setContent(notificationView); /* 4. Create Notification and use Manager to launch it */ Notification notification = builder.getNotification(); String ns = Context.NOTIFICATION_SERVICE; notifManager = (NotificationManager) getSystemService(ns); notifManager.notify(NOTIFICATION_ID, notification); startForeground(NOTIFICATION_ID, notification); }
From source file:com.linkbubble.MainApplication.java
public static boolean openInBrowser(Context context, Intent intent, boolean showToastIfNoBrowser, boolean braveBrowser) { boolean activityStarted = false; ComponentName defaultBrowserComponentName = Settings.get().getDefaultBrowserComponentName(context); if (defaultBrowserComponentName != null) { intent.setComponent(defaultBrowserComponentName); context.startActivity(intent);/* w w w . ja v a 2s .co m*/ activityStarted = true; CrashTracking.log("MainApplication.openInBrowser()"); } else if (braveBrowser) { try { Intent gpsIntent = new Intent(Intent.ACTION_VIEW); gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); gpsIntent.setData(Uri.parse("market://details?id=" + context.getResources().getString(R.string.tab_based_browser_id_name))); context.startActivity(gpsIntent); activityStarted = true; Settings settings = Settings.get(); if (null != settings) { settings.initiateBrowsersUpdate(); } } catch (android.content.ActivityNotFoundException anfe) { CrashTracking.log("MainApplication.openInBrowser() could not open google play"); } } if (activityStarted == false && showToastIfNoBrowser) { Toast.makeText(context, R.string.no_default_browser, Toast.LENGTH_LONG).show(); } return activityStarted; }
From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java
static public void presetDirections(Context context, Location from, Location via, Location to) { Intent intent = new Intent(context, MainActivity.class); intent.setAction(DirectionsFragment.TAG); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("from", new WrapLocation(from)); intent.putExtra("via", new WrapLocation(via)); intent.putExtra("to", new WrapLocation(to)); intent.putExtra("search", false); context.startActivity(intent);//w w w . jav a2 s .c o m }
From source file:de.grobox.liberario.activities.MainActivity.java
public void onNetworkProviderChanged() { // create an intent for restarting this activity Intent intent = new Intent(this, MainActivity.class); intent.setAction(getCurrentFragmentTag()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); finish();/* w w w. j a va 2 s. c o m*/ startActivity(intent); }
From source file:com.radiusnetworks.scavengerhunt.ScavengerHuntApplication.java
@Override /**/*from w w w .j a v a2s .com*/ * Called whenever the Proximity Kit manager sees registered beacons. * * @param beacons a collection of <code>ProximityKitBeacon</code> instances seen in the most * recent ranging cycle. * @param region The <code>ProximityKitBeaconRegion</code> instance that was used to start * ranging for these beacons. */ public void didRangeBeaconsInRegion(Collection<ProximityKitBeacon> beacons, ProximityKitBeaconRegion region) { Log.d(TAG, "didRangeBeaconsInRegion: size=" + beacons.size() + " region=" + region); for (ProximityKitBeacon beacon : beacons) { Log.i(TAG, "ranged beacon: " + beacon.getId1() + " " + beacon.getId2() + " " + beacon.getId3()); String huntId = null; Double triggerDistanceMeters = MINIMUM_TRIGGER_DISTANCE_METERS; Map<String, String> beaconData = beacon.getAttributes(); if (beaconData != null) { huntId = beaconData.get("hunt_id"); if (beaconData.get("trigger_distance") != null) { triggerDistanceMeters = Double.parseDouble(beaconData.get("trigger_distance")); } } if (huntId == null) { Log.d(TAG, "The beacon I just saw is not part of the scavenger hunt, according to ProximityKit"); return; } if (hunt == null) { // Hunt has not been initialized from PK yet. Ignoring all beacons return; } TargetItem target = hunt.getTargetById(huntId); if (target == null) { Log.w(TAG, "The beacon I just saw has a hunt_id of " + huntId + ", but it was not part of the scavenger hunt when this app was started."); return; } if (hunt.getElapsedTime() != 0) { long timeTargetNotifLastSent = target.getTimeNotifLastSent(); long currentTimeMsecs = System.currentTimeMillis(); // Logic to determine when a local notification will be sent if ((currentTimeMsecs - timeTargetNotifLastSent) > REPEAT_NOTIF_RESTRICTED_PERIOD_MSECS && hunt.allowNotification() && (isApplicationSentToBackground(this.getApplicationContext())) && !target.isFound()) { Log.i(TAG, "Sending notification"); sendNotification(); target.setTimeNotifLastSent(currentTimeMsecs); } if (beacon.getDistance() < triggerDistanceMeters && !target.isFound()) { Log.i(TAG, "Found an item. beacon.getAccuracy(): " + beacon.getDistance()); target.setFound(true); hunt.saveToPreferences(this); if (collectionActivity != null) { collectionActivity.showItemFound(); if (hunt.everythingFound()) { // switch to FinishedActivity to show player he/she has won Log.d(TAG, "game is won"); cancelAllNotifications(); Intent i = new Intent(collectionActivity, FinishedActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } } else { Log.i(TAG, "null collection activity"); } } else { if (target.isFound()) { Log.d(TAG, "Not marking this target as found because it is already found"); } else if (beacon.getDistance() < triggerDistanceMeters) { Log.d(TAG, "Not marking this target as found because it isn't close enough. it needs to be under " + triggerDistanceMeters + " but is " + beacon.getDistance()); } } } else { Log.d(TAG, "hunt hasn't started, so all beacon detections are being ignored"); } if (itemActivity != null) { itemActivity.updateDistance(beacon, beaconData); } } }
From source file:com.example.controller.cast.CastRemoteDisplayActivity.java
private void startCastService(CastDevice castDevice) { Intent intent = new Intent(CastRemoteDisplayActivity.this, CastRemoteDisplayActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent notificationPendingIntent = PendingIntent.getActivity(CastRemoteDisplayActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); CastRemoteDisplayLocalService.NotificationSettings settings = new CastRemoteDisplayLocalService.NotificationSettings.Builder() .setNotificationPendingIntent(notificationPendingIntent).build(); CastRemoteDisplayLocalService.Callbacks callbacks = new CastRemoteDisplayLocalService.Callbacks() { @Override//from w w w.j ava 2s. c o m public void onServiceCreated(CastRemoteDisplayLocalService service) { //TODO start a certain presentation here Log.d(TAG, "onServiceCreated"); } @Override public void onRemoteDisplaySessionStarted(CastRemoteDisplayLocalService service) { createPresentation((CastServiceController) service); Log.d(TAG, "onServiceStarted"); } @Override public void onRemoteDisplaySessionError(Status errorReason) { int code = errorReason.getStatusCode(); Log.d(TAG, "onServiceError: " + errorReason.getStatusCode()); initError(); mCastDevice = null; CastRemoteDisplayActivity.this.finish(); } }; CastRemoteDisplayLocalService.startService(CastRemoteDisplayActivity.this, RemoteDisplayService.class, getString(R.string.app_id), castDevice, settings, callbacks); }
From source file:de.badaix.snapcast.MainActivity.java
private void startSnapclient() { if (TextUtils.isEmpty(host)) return;//from w w w . j a v a 2 s . c o m Intent i = new Intent(this, SnapclientService.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); i.putExtra(SnapclientService.EXTRA_HOST, host); i.putExtra(SnapclientService.EXTRA_PORT, port); i.setAction(SnapclientService.ACTION_START); startService(i); }
From source file:io.github.runassudo.ptoffline.utils.TransportrUtils.java
static public void findDirections(Context context, Location from, Location via, Location to, Date date) { Intent intent = new Intent(context, MainActivity.class); intent.setAction(DirectionsFragment.TAG); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("from", new WrapLocation(from)); intent.putExtra("via", new WrapLocation(via)); intent.putExtra("to", new WrapLocation(to)); intent.putExtra("search", true); if (date != null) { intent.putExtra("date", date); }//ww w. ja va 2s . c o m context.startActivity(intent); }