List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP
int FLAG_ACTIVITY_CLEAR_TOP
To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.
Click Source Link
From source file:com.dycody.android.idealnote.async.DataBackupIntentService.java
/** * Creation of notification on operations completed *///from w w w. jav a2 s . c o m private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) { // The behavior differs depending on intent action Intent intentLaunch; if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction()) || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) { intentLaunch = new Intent(mContext, MainActivity.class); intentLaunch.setAction(Constants.ACTION_RESTART_APP); } else { intentLaunch = new Intent(); } // Add this bundle to the intent intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Creates the PendingIntent PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch, PendingIntent.FLAG_UPDATE_CURRENT); NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext); mNotificationsHelper .createNotification(com.dycody.android.idealnote.R.drawable.ic_content_save_white_24dp, title, notifyIntent) .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null)) .setLedActive(); if (prefs.getBoolean("settings_notification_vibration", true)) mNotificationsHelper.setVibration(); mNotificationsHelper.show(); }
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);//w ww.jav a2 s . c om notificationBuilder.addAction(android.R.drawable.ic_menu_add, getString(R.string.Waypoint), pendingIntentWaypoint); Notification notification = notificationBuilder.build(); return notification; }
From source file:com.android.music.MediaPlaybackActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { badSymptoms.saveMenu("menu", item.toString()); Intent intent;// w w w .ja va 2 s . c o m try { switch (item.getItemId()) { case GOTO_START: intent = new Intent(); intent.setClass(this, MusicBrowserActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); break; case USE_AS_RINGTONE: { // Set the system setting to make this the current ringtone if (mService != null) { MusicUtils.setRingtone(this, mService.getAudioId()); } return true; } case PARTY_SHUFFLE: MusicUtils.togglePartyShuffle(); setShuffleButtonImage(); break; case NEW_PLAYLIST: { intent = new Intent(); intent.setClass(this, CreatePlaylist.class); startActivityForResult(intent, NEW_PLAYLIST); return true; } case PLAYLIST_SELECTED: { long[] list = new long[1]; list[0] = MusicUtils.getCurrentAudioId(); long playlist = item.getIntent().getLongExtra("playlist", 0); MusicUtils.addToPlaylist(this, list, playlist); return true; } case DELETE_ITEM: { if (mService != null) { long[] list = new long[1]; list[0] = MusicUtils.getCurrentAudioId(); Bundle b = new Bundle(); String f; if (android.os.Environment.isExternalStorageRemovable()) { f = getString(R.string.delete_song_desc, mService.getTrackName()); } else { f = getString(R.string.delete_song_desc_nosdcard, mService.getTrackName()); } b.putString("description", f); b.putLongArray("items", list); intent = new Intent(); intent.setClass(this, DeleteItems.class); intent.putExtras(b); startActivityForResult(intent, -1); } return true; } case EFFECTS_PANEL: { Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL); i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mService.getAudioSessionId()); startActivityForResult(i, EFFECTS_PANEL); return true; } } } catch (RemoteException ex) { } return super.onOptionsItemSelected(item); }
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.aniruddhc.acemusic.player.AsyncTasks.AsyncAutoGetAlbumArtTask.java
@Override protected void onPostExecute(Void arg0) { Intent intent = new Intent(mContext, AutoFetchAlbumArtService.class); mContext.stopService(intent);/*from w ww .j av a 2 s .c o m*/ if (pd.isShowing() && DIALOG_VISIBLE == true) { pd.dismiss(); } //Dismiss the notification. AutoFetchAlbumArtService.builder .setTicker(mContext.getResources().getString(R.string.done_downloading_art)); AutoFetchAlbumArtService.builder .setContentTitle(mContext.getResources().getString(R.string.done_downloading_art)); AutoFetchAlbumArtService.builder.setSmallIcon(R.drawable.notif_icon); AutoFetchAlbumArtService.builder.setContentInfo(null); AutoFetchAlbumArtService.builder.setContentText(null); AutoFetchAlbumArtService.builder.setProgress(0, 0, false); AutoFetchAlbumArtService.notification = AutoFetchAlbumArtService.builder.build(); AutoFetchAlbumArtService.notification.flags = Notification.FLAG_AUTO_CANCEL; NotificationManager notifyManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notifyManager.notify(AutoFetchAlbumArtService.NOTIFICATION_ID, AutoFetchAlbumArtService.notification); Toast.makeText(mContext, R.string.done_downloading_art, Toast.LENGTH_LONG).show(); //Rescan for album art. //Seting the "RESCAN_ALBUM_ART" flag to true will force MainActivity to rescan the folders. sharedPreferences.edit().putBoolean("RESCAN_ALBUM_ART", true).commit(); //Restart the app. final Intent i = mActivity.getBaseContext().getPackageManager() .getLaunchIntentForPackage(mActivity.getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); mActivity.startActivity(i); mActivity.finish(); }
From source file:org.gaeproxy.GAEProxyService.java
@Override public void onCreate() { super.onCreate(); mShutdownReceiver = new BroadcastReceiver() { @Override/*from w w w . j a va 2 s . com*/ public void onReceive(Context context, Intent intent) { stopSelf(); } }; IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN); registerReceiver(mShutdownReceiver, filter); EasyTracker.getTracker().trackEvent("service", "start", getVersionName(), 0L); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); settings = PreferenceManager.getDefaultSharedPreferences(this); Intent intent = new Intent(this, GAEProxyActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pendIntent = PendingIntent.getActivity(this, 0, intent, 0); notification = new Notification(); try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; } try { mSetForeground = getClass().getMethod("setForeground", mSetForegroundSignature); } catch (NoSuchMethodException e) { throw new IllegalStateException("OS doesn't have Service.startForeground OR Service.setForeground!"); } }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private Intent notificationIntent(final Bundle pushBundle, final String campaignId, final int requestId, final String intentAction, final Class<?> targetClass) { final Intent notificationIntent = new Intent(pinpointContext.getApplicationContext(), targetClass); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.setAction(intentAction); notificationIntent.putExtras(pushBundle); notificationIntent.putExtra(INTENT_SNS_NOTIFICATION_FROM, AWS_EVENT_TYPE_OPENED); notificationIntent.putExtra(CAMPAIGN_ID_PUSH_KEY, campaignId); notificationIntent.putExtra(REQUEST_ID, requestId); notificationIntent.setPackage(pinpointContext.getApplicationContext().getPackageName()); return notificationIntent; }
From source file:com.markupartist.sthlmtraveling.PlannerFragment.java
/** * Setup a search short cut.//from ww w. j av a 2 s . c o m * * @param startPoint * the start point * @param endPoint * the end point */ protected void onCreateShortCut(Site startPoint, Site endPoint, String name) { Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint, null, true); Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, getActivity(), RoutesActivity.class); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Then, set up the container intent (the response to the caller) Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.shortcut); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); // Now, return the result to the launcher getActivity().setResult(Activity.RESULT_OK, intent); getActivity().finish(); }
From source file:com.andrewshu.android.reddit.common.Common.java
/** http://developer.android.com/guide/topics/ui/actionbar.html#Home */ public static void goHome(Activity activity) { // app icon in action bar clicked; go home Intent intent = new Intent(activity, ThreadsListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(intent);/*w w w . j a va 2 s.c om*/ }
From source file:io.teak.sdk.Teak.java
@Override public void onReceive(Context inContext, Intent intent) { final Context context = inContext.getApplicationContext(); if (!Teak.isEnabled()) { Log.e(LOG_TAG, "Teak is disabled, ignoring onReceive()."); return;// w ww. j a v a2s. co m } String action = intent.getAction(); if (GCM_RECEIVE_INTENT_ACTION.equals(action)) { final TeakNotification notif = TeakNotification.remoteNotificationFromIntent(context, intent); if (notif == null) { return; } // Send Notification Received Metric Session.whenUserIdIsReadyRun(new Session.SessionRunnable() { @Override public void run(Session session) { HashMap<String, Object> payload = new HashMap<>(); payload.put("app_id", session.appConfiguration.appId); payload.put("user_id", session.userId()); payload.put("platform_id", notif.teakNotifId); new Request("/notification_received", payload, session).run(); } }); } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_OPENED_INTENT_ACTION_SUFFIX)) { Bundle bundle = intent.getExtras(); // Cancel any updates pending TeakNotification.cancel(context, bundle.getInt("platformId")); // Launch the app if (!bundle.getBoolean("noAutolaunch")) { if (Teak.isDebug) { Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId") + ") opened, auto-launching app."); } Intent launchIntent = context.getPackageManager() .getLaunchIntentForPackage(context.getPackageName()); launchIntent.addCategory("android.intent.category.LAUNCHER"); launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); launchIntent.putExtras(bundle); if (bundle.getString("deepLink") != null) { launchIntent.setData(Uri.parse(bundle.getString("deepLink"))); } context.startActivity(launchIntent); } else { if (Teak.isDebug) { Log.d(LOG_TAG, "Notification (" + bundle.getString("teakNotifId") + ") opened, NOT auto-launching app (noAutoLaunch flag present, and set to true)."); } } // Send broadcast if (Teak.localBroadcastManager != null) { Intent broadcastEvent = new Intent(TeakNotification.LAUNCHED_FROM_NOTIFICATION_INTENT); broadcastEvent.putExtras(bundle); Teak.localBroadcastManager.sendBroadcast(broadcastEvent); } } else if (action.endsWith(TeakNotification.TEAK_NOTIFICATION_CLEARED_INTENT_ACTION_SUFFIX)) { Bundle bundle = intent.getExtras(); TeakNotification.cancel(context, bundle.getInt("platformId")); } }