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.example.crudcontent.activity.EditCityActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(this); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NavUtils.navigateUpTo(this, intent); return true; case R.id.action_delete: BasicCRUDIntentService.performDelete(this, CityContract.URI).whereMatchesId(cityId).start(); finish();/*from w ww . jav a 2 s . c o m*/ return true; } return super.onOptionsItemSelected(item); }
From source file:com.tinfoil.sms.utility.MessageService.java
@Override public int onStartCommand(final Intent intent, final int flags, final int startId) { TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); /*// w ww. j ava 2s .co m * Creates a notification if there is one to be created and if the user set the preferences * to allow notifications */ if (contentTitle != null && contentText != null && sharedPrefs.getBoolean(QuickPrefsActivity.NOTIFICATION_BAR_SETTING_KEY, true)) { Intent notifyIntent = null; PendingIntent in = null; final String address = contentTitle.toString(); if (dba.getUnreadMessageCount() > 1) { MessageService.mNotificationManager.cancel(SINGLE); //Might need to change this. contentTitle = dba.getRow(address).getName(); contentTitle = this.getString(R.string.new_message_notification_title); contentText = dba.getUnreadMessageCount() + " " + this.getString(R.string.unread_email_message); // Extra is added so the user will be brought to the main menu notifyIntent = new Intent(this.getApplicationContext(), ConversationView.class); //notifyIntent.putExtra(multipleNotificationIntent, true); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); in = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(in).setContentTitle(contentTitle).setContentText(contentText) .setTicker(contentTitle + ": " + contentText).setSmallIcon(R.drawable.tinfoil_logo); mNotificationManager.notify(MULTI, builder.build()); } else { contentTitle = dba.getRow(address).getName(); notifyIntent = new Intent(this.getApplicationContext(), SendMessageActivity.class); notifyIntent.putExtra(ConversationView.MESSAGE_INTENT, ConversationView.MESSAGE_VIEW); notifyIntent.putExtra(notificationIntent, address); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Adds the back stack stackBuilder.addParentStack(SendMessageActivity.class); notifyIntent.putExtra(multipleNotificationIntent, false); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(notifyIntent); in = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(in).setContentTitle(contentTitle).setContentText(contentText) .setTicker(contentTitle + ": " + contentText).setSmallIcon(R.drawable.tinfoil_logo); mNotificationManager.notify(SINGLE, builder.build()); } } if (sharedPrefs.getBoolean(QuickPrefsActivity.NOTIFICATION_BAR_SETTING_KEY, true)) { ArrayList<Entry> keyMessage = dba.getAllKeyExchangeMessages(); if (keyMessage != null && keyMessage.size() > 0) { Intent notifyIntent = null; PendingIntent in = null; notifyIntent = new Intent(this.getApplicationContext(), KeyExchangeManager.class); notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // Adds the back stack stackBuilder.addParentStack(KeyExchangeManager.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(notifyIntent); in = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(in) .setContentTitle(this.getString(R.string.pending_key_exchange_notification)) .setContentText(this.getString(R.string.pending_key_exchange_message)) .setTicker(this.getString(R.string.pending_key_exchange_notification)) .setSmallIcon(R.drawable.key_exchange); mNotificationManager.notify(KEY, builder.build()); } else { MessageService.mNotificationManager.cancel(MessageService.KEY); } } this.stopSelf(); return Service.START_NOT_STICKY; }
From source file:com.torrenttunes.android.ui.PlaybackControlsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true);/*from w ww .j a v a 2s . c o m*/ mPlayPause.setOnClickListener(mButtonListener); mTitle = (TextView) rootView.findViewById(R.id.title); mSubtitle = (TextView) rootView.findViewById(R.id.artist); mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info); mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art); rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); MediaMetadataCompat metadata = mMediaControllerProvider.getSupportMediaController().getMetadata(); if (metadata != null) { intent.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription()); } startActivity(intent); } }); return rootView; }
From source file:com.bayapps.android.robophish.ui.PlaybackControlsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true);// w ww. j a v a 2s. c om mPlayPause.setOnClickListener(mButtonListener); mTitle = (TextView) rootView.findViewById(R.id.title); mSubtitle = (TextView) rootView.findViewById(R.id.artist); mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info); mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art); rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController(); MediaMetadataCompat metadata = controller.getMetadata(); if (metadata != null) { intent.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription()); } startActivity(intent); } }); return rootView; }
From source file:de.dreier.mytargets.utils.IntentWrapper.java
public IntentWrapper clearTopSingleTop() { intent.addFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); return this; }
From source file:de.qspool.clementineremote.backend.downloader.DownloadManager.java
private PendingIntent buildNotificationIntent() { Intent intent = new Intent(mContext, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(ClementineMediaSessionNotification.EXTRA_NOTIFICATION_ID, NOTIFICATION_ID_DOWNLOADS); // Create a TaskStack, so the app navigates correctly backwards TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent);/* w w w .j a v a 2s .com*/ return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.viettel.dms.util.StatusNotificationHandler.java
/** * /*from w w w . ja v a2s . c om*/ * tao notification len status notification * @author: AnhND * @param appContext * @param activity * @return: void * @throws: */ private void postNotificationMessage(GlobalBaseActivity activity) { NotificationManager notificationManager = (NotificationManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.NOTIFICATION_SERVICE); int icon = R.drawable.icon_app_small; BitmapDrawable bd = (BitmapDrawable) GlobalInfo.getInstance().getAppContext().getResources() .getDrawable(icon); int iconWidth = bd.getBitmap().getWidth(); CharSequence tickerText = getMessageNotify(); long when = System.currentTimeMillis(); // noi dung trong status bar khi keo xuong xem thong bao CharSequence contentText = Constants.STR_BLANK; contentText = getMessageNotify(); int screenWidth = ((WindowManager) GlobalInfo.getInstance().getAppContext() .getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); screenWidth -= iconWidth;//for icon TextView textView = new TextView(GlobalInfo.getInstance().getAppContext()); int count = tickerText.length(); StringBuilder wrapTickerText = new StringBuilder(); wrapTickerText.append(tickerText); while (count > 0) { if (count < tickerText.length()) { wrapTickerText.append("..."); } float measuredWidth = textView.getPaint().measureText(wrapTickerText.toString()); if (measuredWidth < screenWidth) { break; } count--; wrapTickerText.setLength(count); } Intent notificationIntent = initIntentMessage(); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau int requestCode = (int) System.currentTimeMillis(); PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // Notification notification = new Notification(icon, wrapTickerText, when); // Intent notificationIntent = initIntentMessage(); // notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // //TamQP: fix bug _ phai truyen requestCode de phan biet PendingIntent lien tiep giong nhau // int requestCode = (int) System.currentTimeMillis(); // PendingIntent contentIntent = PendingIntent.getActivity(GlobalInfo.getInstance().getAppContext(), requestCode, notificationIntent, 0); // // notification.setLatestEventInfo(GlobalInfo.getInstance().getAppContext(), StringUtil.getString(R.string.app_name), contentText, contentIntent); // notification.flags |= Notification.FLAG_AUTO_CANCEL; // notification.defaults = Notification.DEFAULT_ALL; // // notificationManager.cancel(NOTIFICATION_MESSAGE_ID); // notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); NotificationCompat.Builder builder = new NotificationCompat.Builder( GlobalInfo.getInstance().getAppContext()); Notification notification = builder.setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(contentText).setWhen(when).setAutoCancel(true) .setContentTitle(StringUtil.getString(R.string.app_name)).setContentText(contentText).build(); notificationManager.cancel(NOTIFICATION_MESSAGE_ID); notificationManager.notify(NOTIFICATION_MESSAGE_ID, notification); }
From source file:com.bobomee.android.common.util.NotificationUtil.java
public static NotificationCompat.Builder setActivityIntent(NotificationCompat.Builder mBuilder, Context context, Intent intent) {// w w w . j a v a 2 s.c o m // ?ACTIONIntent intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(pendingIntent); return mBuilder; }
From source file:com.tcnr14.example.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w w w.j a v a2 s .c om private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MainActivity.class); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.murati.oszk.audiobook.ui.PlaybackControlsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false); mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause); mPlayPause.setEnabled(true);/* w w w .ja va2 s .c o m*/ mPlayPause.setOnClickListener(mButtonListener); mTitle = (TextView) rootView.findViewById(R.id.title); mSubtitle = (TextView) rootView.findViewById(R.id.artist); mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info); mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art); rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity()); MediaMetadataCompat metadata = controller.getMetadata(); if (metadata != null) { intent.putExtra(MusicPlayerActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription()); } startActivity(intent); } }); return rootView; }