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:de.grobox.liberario.utils.TransportrUtils.java
static public void findDepartures(Context context, Location loc) { Intent intent = new Intent(context, MainActivity.class); intent.setAction(DeparturesFragment.TAG); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("location", loc); context.startActivity(intent);//from ww w . j ava2 s . c om }
From source file:at.alladin.rmbt.android.test.RMBTLoopService.java
private NotificationCompat.Builder createNotificationBuilder() { final Resources res = getResources(); 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 NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_icon_loop) .setContentTitle(res.getText(R.string.loop_notification_title)) .setTicker(res.getText(R.string.loop_notification_ticker)).setContentIntent(openAppIntent); setNotificationText(builder);/*w w w . ja va 2s . c o m*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { if (SHOW_DEV_BUTTONS) { final Intent stopIntent = new Intent(ACTION_STOP, null, getApplicationContext(), getClass()); final PendingIntent stopPIntent = PendingIntent.getService(getApplicationContext(), 0, stopIntent, 0); final Intent forceIntent = new Intent(ACTION_FORCE, null, getApplicationContext(), getClass()); final PendingIntent forcePIntent = PendingIntent.getService(getApplicationContext(), 0, forceIntent, 0); addActionToNotificationBuilder(builder, stopPIntent, forcePIntent); } } return builder; }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
/** * Manage the room presence./*from w w w . ja va2 s. c o m*/ * Check the URL room ID format: if room ID is provided as an alias, we translate it * into its corresponding room ID. * * @param aContext the context */ private void manageRoom(final Context aContext, final String roomAlias) { final String roomIdOrAlias = mParameters.get(ULINK_ROOM_ID_OR_ALIAS_KEY); Log.d(LOG_TAG, "manageRoom roomIdOrAlias"); // sanity check if (TextUtils.isEmpty(roomIdOrAlias)) { return; } if (roomIdOrAlias.startsWith("!")) { // usual room Id format (not alias) final RoomPreviewData roomPreviewData = new RoomPreviewData(mSession, roomIdOrAlias, mParameters.get(ULINK_EVENT_ID_KEY), roomAlias, mParameters); Room room = mSession.getDataHandler().getRoom(roomIdOrAlias, false); // if the room exists if ((null != room) && !room.isInvited()) { openRoomActivity(aContext); } else { CommonActivityUtils.previewRoom(VectorApp.getCurrentActivity(), mSession, roomIdOrAlias, roomPreviewData, null); } } else { // room ID is provided as a room alias: get corresponding room ID Log.d(LOG_TAG, "manageRoom : it is a room Alias"); // Start the home activity with the waiting view enabled, while the URL link // is processed in the receiver. The receiver, once the URL was parsed, will stop the waiting view. 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); mSession.getDataHandler().roomIdByAlias(roomIdOrAlias, new ApiCallback<String>() { @Override public void onSuccess(final String roomId) { Log.d(LOG_TAG, "manageRoom : retrieve the room ID " + roomId); if (!TextUtils.isEmpty(roomId)) { mParameters.put(ULINK_ROOM_ID_OR_ALIAS_KEY, roomId); manageRoom(aContext, roomIdOrAlias); } } private void onError(String errorMessage) { CommonActivityUtils.displayToast(aContext, errorMessage); stopHomeActivitySpinner(aContext); } @Override public void onNetworkError(Exception e) { onError(e.getLocalizedMessage()); } @Override public void onMatrixError(MatrixError e) { onError(e.getLocalizedMessage()); } @Override public void onUnexpectedError(Exception e) { onError(e.getLocalizedMessage()); } }); } }
From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java
private void setupForegroundDispatch() { /* initialize the PendingIntent to start for the dispatch */ nfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); /* initialize the IntentFilters to override dispatching for */ nfcIntentFilters = new IntentFilter[3]; nfcIntentFilters[0] = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); nfcIntentFilters[0].addCategory(Intent.CATEGORY_DEFAULT); nfcIntentFilters[1] = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); nfcIntentFilters[1].addCategory(Intent.CATEGORY_DEFAULT); nfcIntentFilters[2] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); nfcIntentFilters[2].addCategory(Intent.CATEGORY_DEFAULT); try {/*from w w w . j a va 2s.c om*/ nfcIntentFilters[0].addDataType("*/*"); // Handle all MIME based dispatches. } catch (IntentFilter.MalformedMimeTypeException e) { Log.e(TAG, "setupForegroundDispatch: " + e.getMessage()); } /* Initialize the tech lists used to perform matching for dispatching of the * ACTION_TECH_DISCOVERED intent */ nfcTechLists = new String[][] {}; }
From source file:de.grobox.liberario.utils.TransportrUtils.java
static public void findNearbyStations(Context context, Location loc) { Intent intent = new Intent(context, MainActivity.class); intent.setAction(NearbyStationsFragment.TAG); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("location", loc); context.startActivity(intent);/*from w w w. ja v a 2 s .co m*/ }
From source file:it.imwatch.nfclottery.MainActivity.java
/** * Sets up the dispatching of NFC events a the foreground Activity. * * @param activity The {@link android.app.Activity} to setup the foreground dispatch for * @param adapter The {@link android.nfc.NfcAdapter} to setup the foreground dispatch for *//* w ww.j a va 2 s .com*/ public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { if (adapter != null) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][] {}; // Notice that this is the same filter we define in our manifest. // This ensures we're not stealing events for other types of NDEF. filters[0] = new IntentFilter(); IntentFilter filter = filters[0]; filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filter.addCategory(Intent.CATEGORY_DEFAULT); try { filter.addDataType(MIME_VCARD); filter.addDataType(MIME_XVCARD); } catch (IntentFilter.MalformedMimeTypeException e) { throw new RuntimeException("Mime type not supported."); } adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); } }
From source file:com.linkbubble.MainApplication.java
public static boolean loadIntent(Context context, Intent intent, String urlAsString, long urlLoadStartTime) { intent.setFlags(//from w ww . j a v a2 s . c o m Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); context.startActivity(intent); //Log.d(TAG, "redirect to app: " + resolveInfo.loadLabel(context.getPackageManager()) + ", url:" + url); if (urlLoadStartTime > -1) { Settings.get().trackLinkLoadTime(System.currentTimeMillis() - urlLoadStartTime, Settings.LinkLoadType.AppRedirectBrowser, urlAsString); } return true; }
From source file:info.guardianproject.notepadbot.NoteCipher.java
void showLockScreen() { Intent intent = new Intent(this, LockScreenActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("originalIntent", getIntent()); startActivity(intent);//w w w .j a v a 2 s .c o m finish(); }
From source file:com.facebook.notifications.NotificationsManager.java
/** * Present a {@link Notification} to be presented from a GCM push bundle. * <p/>//w ww . ja va2 s.c o m * This does not present a notification immediately, instead it caches the assets from the * notification bundle, and then presents a notification to the user. This allows for a smoother * interaction without loading indicators for the user. * <p/> * Note that only one notification can be created for a specific push bundle, should you attempt * to present a new notification with the same payload bundle as an existing notification, it will * replace and update the old notification. * * @param context The context to send the notification from * @param notificationBundle The content of the push notification * @param launcherIntent The launcher intent that contains your Application's activity. * This will be modified with the FLAG_ACTIVITY_CLEAR_TOP and * FLAG_ACTIVITY_SINGLE_TOP flags, in order to properly show the * notification in an already running application. * <p/> * Should you not want this behavior, you may use the notificationExtender * parameter to customize the contentIntent of the notification before * presenting it. * @param notificationExtender A nullable argument that allows you to customize the notification * before displaying it. Use this to configure Icons, text, sounds, * etc. before we pass the notification off to the OS. */ public static boolean presentNotification(@NonNull final Context context, @NonNull final Bundle notificationBundle, @NonNull final Intent launcherIntent, @Nullable final NotificationExtender notificationExtender) { final JSONObject alert; final int payloadHash; try { String payload = notificationBundle.getString(CARD_PAYLOAD_KEY); if (payload == null) { return false; } payloadHash = payload.hashCode(); JSONObject payloadObject = new JSONObject(payload); alert = payloadObject.optJSONObject("alert") != null ? payloadObject.optJSONObject("alert") : new JSONObject(); } catch (JSONException ex) { Log.e(LOG_TAG, "Error while parsing notification bundle JSON", ex); return false; } final boolean[] success = new boolean[1]; final Thread backgroundThread = new Thread(new Runnable() { @Override public void run() { Looper.prepare(); prepareCard(context, notificationBundle, new PrepareCallback() { @Override public void onPrepared(@NonNull Intent presentationIntent) { Intent contentIntent = new Intent(launcherIntent); contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent.putExtra(EXTRA_PAYLOAD_INTENT, presentationIntent); NotificationManager manager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder(context) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setContentTitle(alert.optString("title")).setContentText(alert.optString("body")) .setAutoCancel(true) .setContentIntent(PendingIntent.getActivity(context.getApplicationContext(), payloadHash, contentIntent, PendingIntent.FLAG_ONE_SHOT)); if (notificationExtender != null) { builder = notificationExtender.extendNotification(builder); } manager.notify(NOTIFICATION_TAG, payloadHash, builder.getNotification()); success[0] = true; Looper.myLooper().quit(); } @Override public void onError(@NonNull Exception exception) { Log.e(LOG_TAG, "Error while preparing card", exception); Looper.myLooper().quit(); } }); Looper.loop(); } }); backgroundThread.start(); try { backgroundThread.join(); } catch (InterruptedException ex) { Log.e(LOG_TAG, "Failed to wait for background thread", ex); return false; } return success[0]; }
From source file:com.nbplus.vbroadlistener.gcm.MyGcmListenerService.java
private void showNotification(Context context, int notificationId, int smallIconId, String title, String contentText, String bigTitle, String bigContentText, String summaryText, String ticker, Intent intent) {/*from w w w. ja v a 2 s. c om*/ NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSound(soundUri); if (smallIconId == 0) { builder.setSmallIcon(R.mipmap.ic_launcher); } else { builder.setSmallIcon(smallIconId); } builder.setWhen(System.currentTimeMillis()); //builder.setNumber(10); if (!StringUtils.isEmptyString(ticker)) { builder.setTicker(ticker); } if (StringUtils.isEmptyString(title)) { builder.setContentTitle(PackageUtils.getApplicationName(context)); } else { builder.setContentTitle(title); } builder.setContentText(contentText); builder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); builder.setAutoCancel(true); // big title and text if (!StringUtils.isEmptyString(bigTitle) && !StringUtils.isEmptyString(bigContentText)) { NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle(builder); if (!StringUtils.isEmptyString(summaryText)) { style.setSummaryText(summaryText); } style.setBigContentTitle(bigTitle); style.bigText(bigContentText); builder.setStyle(style); } if (intent != null) { intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); } notificationManager.notify(notificationId, builder.build()); }