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.baasio.sample.startup.gcm.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w w w . ja v a 2 s . co m 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); 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 notification = new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon) .setContentTitle(context.getString(R.string.app_name)).setContentText(message) .setContentIntent(intent).setTicker(message).setAutoCancel(true).getNotification(); notificationManager.notify(0, notification); }
From source file:com.cfc.needblood.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//* ww w.jav a 2 s . c o m*/ private static void generateNotification(Context context, String message) { long when = System.currentTimeMillis(); 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 contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Change the icons to conform Android's design guildeline builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bd_icon)) .setTicker(message).setWhen(when).setAutoCancel(true) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.notification_message)); Notification notification = builder.build(); notificationManager.notify(0, notification); // Notification sound, comment out if do not need Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, ringtone); r.play(); }
From source file:com.kth.baasio.baassample.gcm.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from w ww . jav a 2 s .c o m 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); Intent notificationIntent = new Intent(context, BaasMainActivity.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 notification = new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon) .setContentTitle(context.getString(R.string.app_name)).setContentText(message) .setContentIntent(intent).setTicker(message).setAutoCancel(true).getNotification(); notificationManager.notify(0, notification); }
From source file:com.macleod2486.androidswissknife.components.NFCTool.java
private void setUpWrite(String message) { Log.i("NFCTool", "Message received " + message); Intent nfcIntent = new Intent(activity.getApplicationContext(), NFCActivity.class); nfcIntent.putExtra("NFCMode", "write"); nfcIntent.putExtra("NFCMessage", message); nfcIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, nfcIntent, 0); IntentFilter filter = new IntentFilter(); filter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED); filter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED); filter.addAction(NfcAdapter.ACTION_TECH_DISCOVERED); IntentFilter[] filterArray = new IntentFilter[] { filter }; String[][] techListsArray = new String[][] { new String[] { Ndef.class.getName() }, new String[] { Ndef.class.getName() } }; adapter.disableReaderMode(activity); adapter.enableForegroundDispatch(activity, pendingIntent, filterArray, techListsArray); Toast.makeText(this.activity, "Please scan tag with device.", Toast.LENGTH_LONG).show(); }
From source file:eu.inmite.apps.smsjizdenka.service.ListenerService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null && intent.getAction() != null) { if ("open_ticket".equals(intent.getAction())) { final Ticket t = (Ticket) intent.getExtras().getSerializable("ticket"); sendMessage("openTicket/" + t.getId(), null); Intent confirmationIntent = new Intent(this, ConfirmationActivity.class); confirmationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); confirmationIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION); startActivity(confirmationIntent); }//www.j a va 2 s. c o m } return super.onStartCommand(intent, flags, startId); }
From source file:com.saarang.samples.apps.iosched.gcm.command.AnnouncementCommand.java
private void displayNotification(Context context, String message) { LogUtils.LOGI(TAG, "Displaying notification: " + message); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification) .setTicker(message)/*from www. j a v a2s . c o m*/ .setContentTitle(context.getString(com.saarang.samples.apps.iosched.R.string.app_name)) .setContentText(message) //.setColor(context.getResources().getColor(R.color.theme_primary)) // Note: setColor() is available in the support lib v21+. // We commented it out because we want the source to compile // against support lib v20. If you are using support lib // v21 or above on Android L, uncomment this line. .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MyScheduleActivity.class).setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 0)) .setAutoCancel(true).build()); }
From source file:info.zamojski.soft.towercollector.collector.CollectorNotificationHelper.java
private PendingIntent createOpenMainActivityIntent() { Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setAction(CollectorService.SERVICE_FULL_NAME + "_NID_" + CollectorService.NOTIFICATION_ID); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); return pendingIntent; }
From source file:be.ppareit.swiftp.gui.FsNotification.java
private void setupNotification(Context context) { Cat.d("Setting up the notification"); // Get NotificationManager reference String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); // get ip address InetAddress address = FsService.getLocalInetAddress(); if (address == null) { Cat.w("Unable to retrieve the local ip address"); return;// w w w . j a v a 2 s. c o m } String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/"; // Instantiate a Notification int icon = R.mipmap.notification; CharSequence tickerText = String.format(context.getString(R.string.notification_server_starting), iptext); long when = System.currentTimeMillis(); // Define Notification's message and Intent CharSequence contentTitle = context.getString(R.string.notification_title); CharSequence contentText = String.format(context.getString(R.string.notification_text), iptext); Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); int stopIcon = android.R.drawable.ic_menu_close_clear_cancel; CharSequence stopText = context.getString(R.string.notification_stop_text); Intent stopIntent = new Intent(FsService.ACTION_STOP_FTPSERVER); PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent, PendingIntent.FLAG_ONE_SHOT); int preferenceIcon = android.R.drawable.ic_menu_preferences; CharSequence preferenceText = context.getString(R.string.notif_settings_text); Intent preferenceIntent = new Intent(context, MainActivity.class); preferenceIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent preferencePendingIntent = PendingIntent.getActivity(context, 0, preferenceIntent, 0); Notification notification = new NotificationCompat.Builder(context).setContentTitle(contentTitle) .setContentText(contentText).setContentIntent(contentIntent).setSmallIcon(icon) .setTicker(tickerText).setWhen(when).setOngoing(true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX) .addAction(stopIcon, stopText, stopPendingIntent) .addAction(preferenceIcon, preferenceText, preferencePendingIntent).setShowWhen(false).build(); // Pass Notification to NotificationManager nm.notify(NOTIFICATION_ID, notification); Cat.d("Notification setup done"); }
From source file:com.willowtreeapps.spurceexampleapp.RecyclerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.sort_option: startActivity(new Intent(this, SpruceActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)); break;// w w w . j av a 2 s. c o m case R.id.recycler_option: break; default: finish(); break; } return super.onOptionsItemSelected(item); }
From source file:com.willowtreeapps.spurceexampleapp.ListViewActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.sort_option: startActivity(new Intent(this, SpruceActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)); break;/* w w w . j a v a 2s .co m*/ case R.id.list_view_option: break; case R.id.recycler_option: startActivity(new Intent(this, RecyclerActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)); break; default: finish(); break; } return super.onOptionsItemSelected(item); }