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:am.roadpolice.roadpolice.alarm.AlarmReceiver.java
@Override public void submissionCompleted(ArrayList<ViolationInfo> list, String result) { // If errors occurs while trying to update data. if (!TextUtils.isEmpty(result)) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, true); ed.apply();/*from w w w.java 2 s. c o m*/ return; } SQLiteHelper dbHelper = new SQLiteHelper(mContext); // Get list of new violation info, if null no new items found. ArrayList<ViolationInfo> newViolationInfoList = dbHelper.insertViolationInfoListAndCheckNew(list); // Create notification. NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext); // Create notification Title Text. int updateInterval = DialogSettings.getUpdateInterval(mContext); switch (updateInterval) { case DialogSettings.DAILY: mBuilder.setContentTitle(mContext.getString(R.string.txtDailyNotification)); break; case DialogSettings.WEEKLY: mBuilder.setContentTitle(mContext.getString(R.string.txtWeeklyNotification)); break; case DialogSettings.MONTHLY: mBuilder.setContentTitle(mContext.getString(R.string.txtMonthlyNotification)); break; } // Create notification message. if (newViolationInfoList == null || newViolationInfoList.size() < 1) { mBuilder.setContentText(mContext.getString(R.string.txtNoViolationNotification)); mBuilder.setSmallIcon(R.drawable.ic_checked); } else { mBuilder.setContentText(mContext.getString(R.string.txtYesViolationNotification)); mBuilder.setSmallIcon(R.drawable.ic_attention); } // Activate vibration and sound. mBuilder.setDefaults(Notification.DEFAULT_SOUND); mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); mBuilder.setAutoCancel(true); // Set intent to open Main Activity, when user click on notification. Intent notificationIntent = new Intent(mContext, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent mainActivityPendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0); mBuilder.setContentIntent(mainActivityPendingIntent); // Show notification. NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build()); // Get shared preferences. SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor ed = sp.edit(); ed.putBoolean(MainActivity.MISS_UPDATE_DUE_TO_NETWORK_ISSUE, false); ed.apply(); }
From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java
private void sendNotification(String msg) { alarmNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String title = getString(R.string.title_activity_main); Intent intent = new Intent(this, AlarmScreenActivity.class); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(); NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(title).setSmallIcon(R.drawable.ic_fab_alarm).setLargeIcon(bitmap) .setCategory(Notification.CATEGORY_ALARM) .setColor(ContextCompat.getColor(getBaseContext(), R.color.colorAccent)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setOngoing(true) .setContentIntent(pendingIntent); alarmNotificationManager.notify(1503, alarmNotificationBuilder.build()); }
From source file:com.linkbubble.MainApplication.java
public static boolean loadIntent(Context context, String packageName, String className, String urlAsString, long urlLoadStartTime, boolean toastOnError) { Intent openIntent = new Intent(Intent.ACTION_VIEW); try {/* w w w . j a v a2 s .co m*/ openIntent.setClassName(packageName, className); openIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); openIntent.setData(Uri.parse(urlAsString)); context.startActivity(openIntent); //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); } CrashTracking.log("MainApplication.loadIntent()"); return true; } catch (Exception ex) { // We want to catch SecurityException || ActivityNotFoundException openIntent = new Intent(Intent.ACTION_VIEW); openIntent.setPackage(packageName); openIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); openIntent.setData(Uri.parse(urlAsString)); try { context.startActivity(openIntent); if (urlLoadStartTime > -1) { Settings.get().trackLinkLoadTime(System.currentTimeMillis() - urlLoadStartTime, Settings.LinkLoadType.AppRedirectBrowser, urlAsString); } CrashTracking.log("MainApplication.loadIntent() [2]"); return true; } catch (SecurityException ex2) { if (toastOnError) { Toast.makeText(context, R.string.unable_to_launch_app, Toast.LENGTH_SHORT).show(); } return false; } catch (ActivityNotFoundException activityNotFoundException) { if (toastOnError) { Toast.makeText(context, R.string.unable_to_launch_app, Toast.LENGTH_SHORT).show(); } return false; } } }
From source file:com.geecko.QuickLyric.MainActivity.java
@Override protected void onResume() { super.onResume(); App.activityResumed();/* w ww . jav a 2s . c o m*/ NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null) { PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, ((Object) this).getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndef.addDataType("application/lyrics"); } catch (IntentFilter.MalformedMimeTypeException e) { return; } IntentFilter[] intentFiltersArray = new IntentFilter[] { ndef, }; try { nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, null); } catch (Exception ignored) { } } LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager() .findFragmentByTag(LYRICS_FRAGMENT_TAG); if (lyricsViewFragment != null) { if (getIntent() == null || getIntent().getAction() == null || getIntent().getAction().equals("")) { // fixme executes twice? if (!"Storage".equals(lyricsViewFragment.getSource()) && !lyricsViewFragment.searchResultLock) lyricsViewFragment.fetchCurrentLyrics(false); lyricsViewFragment.checkPreferencesChanges(); } } AppBarLayout appBarLayout = (AppBarLayout) findViewById(id.appbar); appBarLayout.removeOnOffsetChangedListener(this); appBarLayout.addOnOffsetChangedListener(this); }
From source file:com.radiusnetworks.museumguide.MuseumGuideApplication.java
public void dependencyLoadFinished() { Log.d(TAG, "all dependencies loaded"); if (ProximityKitManager.getInstanceForApplication(this).getKit() == null || museum == null || museum.getItemList().size() == 0) { dependencyLoadingFailed("Network error", "Can't access museum data. Please verify your network connection and try again."); return;/*www. j a va2 s .c om*/ } List<String> missingAssets = getMissingAssetList(); if (missingAssets.size() == 0) { // Yes, we have everything we need to start up. Let's start the image activity with the first exhibit item Intent i = new Intent(loadingActivity, MuseumItemsActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); i.putExtra("item_id", museum.getItemList().get(0).getId()); startActivity(i); this.loadingActivity.finish(); // do this so that if we hit back, the loading activity won't show up again return; } else { dependencyLoadingFailed("Error loading museum", "Can't download images and/or html." + " Please verify your network connection and try again. Missing items: " + missingAssets.toString().replaceAll("(^\\[|\\]$)", "")); return; } }
From source file:de.grobox.liberario.utils.TransportrUtils.java
static public void findDirections(Context context, WrapLocation from, @Nullable WrapLocation via, WrapLocation to, @Nullable Date date, boolean search) { Intent intent = new Intent(context, DirectionsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(FROM, from);/*from w ww . jav a 2 s . c o m*/ intent.putExtra(VIA, via); intent.putExtra(TO, to); intent.putExtra(SEARCH, search); if (date != null) { intent.putExtra(DATE, date); } context.startActivity(intent); }
From source file:com.googlecode.eyesfree.brailleback.BrailleBackService.java
public boolean runHelp() { Intent intent = new Intent(this, KeyBindingsActivity.class); intent.addFlags(//from ww w. j a va2 s .c o m Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); return true; }
From source file:com.dosse.bwentrain.androidPlayer.MainActivity.java
@Override //receives intents from DetailsActivity, and loads the selected preset. if no path is set, then the intent came from some other activity and does nothing public void onNewIntent(Intent i) { String request = i.getStringExtra("path"); if (request != null) { Preset p = loadPreset(request);//from w w w. j a v a 2 s. c om if (pc == null) { //I got some bug reports where the PlayerController was null. This should not be possible, and I was not able to replicate the bug so I'll just try to restart the activity. Hopefully it will fix the bug? startActivity(new Intent(this, MainActivity.class).putExtra("path", request) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)); finish(); } if (p != null) pc.setPreset(p); else Toast.makeText(getApplicationContext(), R.string.load_error, Toast.LENGTH_SHORT).show(); } super.onNewIntent(i); }
From source file:com.otaupdater.utils.Utils.java
public static void showProKeyOnlyFeatureDialog(final Context ctx, final DialogCallback callback) { AlertDialog.Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.prokey_only_feature_title); builder.setMessage(R.string.prokey_only_feature_message); builder.setPositiveButton(R.string.prokey_only_get, new DialogInterface.OnClickListener() { @Override//from ww w .j a v a 2 s. c o m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Intent i = new Intent(ctx, SettingsActivity.class); i.setAction(SettingsActivity.EXTRA_SHOW_GET_PROKEY_DLG); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); ctx.startActivity(i); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); final AlertDialog dlg = builder.create(); dlg.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { if (callback != null) callback.onDialogShown(dlg); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (callback != null) callback.onDialogClosed(dlg); } }); dlg.show(); }
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
private static void generateImageNotification(Context context, String title, String message, String url, String image_url, String large_icon) { // The bitmap to download Bitmap message_bitmap = null;/*from w w w .j a va2 s. c om*/ // Should we download the image? if ((image_url != null) && (!image_url.equals(""))) { message_bitmap = AirBopImageDownloader.downloadBitmap(image_url, context); } // If we didn't get the image, we're out of here if (message_bitmap == null) { generateNotification(context, title, message, url, large_icon); return; } 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(); } } } } 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.BigPictureStyle().bigPicture(message_bitmap)); 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); }