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.lofland.housebot.BotController.java
public void startCamera() { // old "return to launcher" intent // Intent launcher = new // Intent().setAction(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME); // To get it not to run ANOTHER instance of House Bot, use the below two // lines for the return // intent for housebot // From://from w w w .j av a 2s . com // http://stackoverflow.com/questions/2424488/android-new-intent-starts-new-instance-with-androidlaunchmode-singletop // Also added android:launchMode="singleTop" to the manifest Intent housebot = new Intent().setClassName(BotController.this, BotController.class.getName()); housebot.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); Intent ipwebcam = new Intent().setClassName("com.pas.webcam", "com.pas.webcam.Rolling") // Original /* * .putExtra("cheats", new String[] { "set(Photo,1024,768)", // set photo resolution to 1024x768 "set(DisableVideo,true)", // Disable video streaming (only photo * and immediate photo) "reset(Port)", // Use default port 8080 "set(HtmlPath,/sdcard/html/)", // Override server pages with ones in this directory }) * .putExtra("hidebtn1", true) // Hide help button .putExtra("caption2", "Run in background") // Change caption on "Actions..." .putExtra("intent2", launcher) // * And give button another purpose .putExtra("returnto", new Intent().setClassName(ApiTest.this,ApiTest.class.getName())); // Set activity to return to */ // Mine .putExtra("cheats", new String[] { "set(Video,640,480)", // set photo resolution to // 1024x768 "reset(Photo)", "reset(DisableVideo)", "set(DisablePhoto,true)", "set(DisablePhotoAF,true)", "set(DisableImmediatePhoto,true)", "set(DisableTorchCtl,true)", "reset(HtmlPath)", "reset(Port)", // Use default port 8080 "set(Awake,true)", "set(Quality,50)" }) .putExtra("hidebtn1", true) // Hide help button .putExtra("caption2", "Run in background") // Change caption on // "Actions..." .putExtra("intent2", housebot); // And give button another // purpose, go to Housebot :) // .putExtra("returnto", housebot ); // Also returns to Housebot // No, then if I exit HouseBot it goes here and then I get a small loop startActivity(ipwebcam); }
From source file:im.vector.fragments.VectorMessageListFragment.java
@Override public void onURLClick(Uri uri) { if (null != uri) { if (null != VectorUniversalLinkReceiver.parseUniversalLink(uri)) { // pop to the home activity Intent intent = new Intent(getActivity(), VectorHomeActivity.class); intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(VectorHomeActivity.EXTRA_JUMP_TO_UNIVERSAL_LINK, uri); getActivity().startActivity(intent); } else {// w w w . j a va2 s .c om Intent intent = new Intent(Intent.ACTION_VIEW, uri); intent.putExtra(Browser.EXTRA_APPLICATION_ID, getActivity().getPackageName()); getActivity().startActivity(intent); } } }
From source file:com.f8full.casserolesencours.CasserolesEnCoursActivity.java
/** * On service click.// w w w.jav a 2 s . c om * * @param view the view */ public void onServiceClick(View view) { boolean isChecked = ((ToggleButton) view).isChecked(); if (isChecked) { //turn on mAlohar.startServices(); //StatusView.setText("Service is running!"); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setText(getString(R.string.geolocationStatusOn)); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setTextColor(getResources().getColor(R.color.text_red)); ((TextView) findViewById(R.id.distanceFilterNA)).setVisibility(View.INVISIBLE); findViewById(R.id.FrequencyGroupLayout).setVisibility(View.VISIBLE); mDistanceFilterSpinner.setEnabled(true); //String freq = ((RadioButton)findViewById( ((RadioGroup)findViewById(R.id.pollFrequencyRadioGroup)).getCheckedRadioButtonId() )).getText().toString(); String text = getString(R.string.geolocationStatusOnNotification);//String.format(getString(R.string.geolocationOnNotification), freq); int icon = R.drawable.ic_launcher; CharSequence tickerText = text; long when = System.currentTimeMillis(); mNotification = new Notification(icon, tickerText, when); mNotification.flags |= Notification.FLAG_ONGOING_EVENT; CharSequence contentText = getString(R.string.geolocationOnNotificationNoFreq); CharSequence contentTitle = getString(R.string.app_name); Intent notificationIntent = new Intent(this, CasserolesEnCoursActivity.class); mNotification.contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); mNotification.setLatestEventInfo(this, contentTitle, contentText, mNotification.contentIntent); mNotificationManager.notify(R.layout.main, mNotification); } else { //turn off mAlohar.stopServices(); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setText(getString(R.string.geolocationStatusOff)); ((TextView) findViewById(R.id.geolocationServiceStatus)) .setTextColor(getResources().getColor(R.color.text_green)); ((TextView) findViewById(R.id.distanceFilterNA)).setVisibility(View.VISIBLE); findViewById(R.id.FrequencyGroupLayout).setVisibility(View.INVISIBLE); mDistanceFilterSpinner.setSelection(0); mDistanceFilterSpinner.setEnabled(false); //((RadioGroup) findViewById(R.id.pollFrequencyRadioGroup)).check(-1); cancelActiveTasks(); mLocationPollThreadExecutor.purge(); //That is a hack, some code path must be missed, I'm tracking a thread leak bug when app is in background for a long time mLocationPollThreadExecutor.shutdown(); mLocationPollThreadExecutor = new ScheduledThreadPoolExecutor(20); mIsStationary = true; mNotificationManager.cancel(R.layout.main); } }
From source file:com.concentriclivers.mms.com.android.mms.transaction.MessagingNotification.java
private static final NotificationInfo getNewMessageNotificationInfo(Context context, boolean isSms, String address, String message, String subject, long threadId, long timeMillis, Bitmap attachmentBitmap, Contact contact, int attachmentType) { // TDH/*from w w w. j a va2s. c om*/ Log.d("NotificationDebug", "getNewMessageNotificationInfo"); Intent clickIntent = ComposeMessageActivity.createIntent(context, threadId); clickIntent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); String senderInfo = buildTickerMessage(context, address, null, null).toString(); String senderInfoName = senderInfo.substring(0, senderInfo.length() - 2); CharSequence ticker = buildTickerMessage(context, address, subject, message); // TDH Log.d("NotificationDebug", "senderInfo: " + senderInfo + ", ticker: " + ticker); return new NotificationInfo(isSms, clickIntent, message, subject, ticker, timeMillis, senderInfoName, attachmentBitmap, contact, attachmentType, threadId); }
From source file:com.bernard.beaconportal.activities.activity.MessageList.java
public static void listAccounts(Context context) { Intent intent = new Intent(context, Accounts.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.putExtra(EXTRA_STARTUP, false); context.startActivity(intent);//from w ww. j av a 2s. c om }
From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java
/** * When a content is processed, we can remove it from SQLite. We can also check if a new one can * be shown.//w w w. ja va 2 s . c om */ void onContentProcessed(EngagementReachContent content) { /* Delete content */ deleteContent(content); /* If loading update loading window to display error message */ if (mState == State.LOADING) { /* Only if not replaced by another loading window */ if (content.getLocalId() == mCurrentShownContentId) { /* We are now idle */ setIdle(); /* * Refresh loading activity saying that the content is now deleted (intent with no id and * isLoading will return false) */ showOrRefreshLoading(content, Intent.FLAG_ACTIVITY_SINGLE_TOP); } } /* If not loading and we were not scanning, set idle and scan for next content */ else if (!mScanning) { /* We are now idle */ setIdle(); /* Look for new in-app content if just exiting an in-app content */ if (!content.isSystemNotification() && !(content instanceof com.microsoft.azure.engagement.reach.EngagementDataPush)) scanContent(false); } }
From source file:de.tudresden.inf.rn.mobilis.mxa.XMPPRemoteService.java
/** * @author Tobias Rho//from w ww.ja v a 2 s .c om */ private void showConnectionNotification() { if (RUN_IN_FOREGROUND) { Notification note = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.sb_txt_title)) .setContentText(getString(R.string.sb_txt_text)).setSmallIcon(R.drawable.stat_notify_chat) .build(); Intent i = new Intent(this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); note.setLatestEventInfo(this, getString(R.string.sb_txt_title), getString(R.string.sb_txt_text), pi); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(NOTIFICATION_ID, note); } else { NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification status = new Notification(R.drawable.stat_notify_chat, getString(R.string.sb_txt_text), System.currentTimeMillis()); status.setLatestEventInfo(XMPPRemoteService.this, getString(R.string.sb_txt_title), getString(R.string.sb_txt_text), PendingIntent.getActivity(XMPPRemoteService.this, 0, new Intent(ConstMXA.INTENT_SERVICEMONITOR), 0)); status.flags |= Notification.FLAG_ONGOING_EVENT; status.icon = R.drawable.stat_notify_chat; nm.notify(XMPPSERVICE_STATUS, status); } }
From source file:co.beem.project.beem.FbTextService.java
public void startForeGroundWithnotification(int statusStringId) { // Notification note=new Notification(R.drawable.ic_stat_pending_notification, // getString(R.string.notification_welcome), // System.currentTimeMillis()); isStartingForeground = true;/*from ww w . j a v a 2s . c o m*/ Intent i = new Intent(this, FbTextMainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); if (statusStringId == 0) { int statusState = mSettings.getInt(FbTextApplication.STATUS_KEY, 0); statusStringId = statusState == 0 ? R.string.notification_online : R.string.notification_invisible; } Notification note = new NotificationCompat.Builder(this).setContentTitle(getString(statusStringId)) .setContentText(getString(R.string.notification_description)) .setSmallIcon(R.drawable.ic_stat_pending_notification).setContentIntent(pi).build(); /*note.setLatestEventInfo(this, getString(statusStringId), getString(R.string.notification_description), pi);*/ note.flags |= Notification.FLAG_NO_CLEAR; startForeground(1080, note); }
From source file:com.concentriclivers.mms.com.android.mms.transaction.MessagingNotification.java
/** * updateNotification is *the* main function for building the actual notification handed to * the NotificationManager//from w w w. ja v a 2 s . c om * @param context * @param isNew if we've got a new message, show the ticker * @param uniqueThreadCount */ private static void updateNotification(Context context, boolean isNew, int uniqueThreadCount) { // TDH Log.d("NotificationDebug", "updateNotification()"); // If the user has turned off notifications in settings, don't do any notifying. if (!MessagingPreferenceActivity.getNotificationEnabled(context)) { if (DEBUG) { Log.d(TAG, "updateNotification: notifications turned off in prefs, bailing"); } // TDH Log.d("NotificationDebug", "Notifications not enabled!"); return; } // Figure out what we've got -- whether all sms's, mms's, or a mixture of both. int messageCount = sNotificationSet.size(); // TDH: Log.d("NotificationDebug", "messageCount: " + messageCount); if (messageCount == 0) { Log.d("NotificationDebug", "WTF. Should have at least one message."); return; } NotificationInfo mostRecentNotification = sNotificationSet.first(); // TDH: Use NotificationCompat2 (and in other places but it is obvious where). final NotificationCompat2.Builder noti = new NotificationCompat2.Builder(context) .setWhen(mostRecentNotification.mTimeMillis); if (isNew) { noti.setTicker(mostRecentNotification.mTicker); } // TDH Log.d("NotificationDebug", "Creating TaskStackBuilder"); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); // TDH Log.d("NotificationDebug", "Created TaskStackBuilder. UniqueThreadCount: " + uniqueThreadCount); // If we have more than one unique thread, change the title (which would // normally be the contact who sent the message) to a generic one that // makes sense for multiple senders, and change the Intent to take the // user to the conversation list instead of the specific thread. // Cases: // 1) single message from single thread - intent goes to ComposeMessageActivity // 2) multiple messages from single thread - intent goes to ComposeMessageActivity // 3) messages from multiple threads - intent goes to ConversationList final Resources res = context.getResources(); String title = null; Bitmap avatar = null; if (uniqueThreadCount > 1) { // messages from multiple threads Intent mainActivityIntent = new Intent(Intent.ACTION_MAIN); mainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); mainActivityIntent.setType("vnd.android-dir/mms-sms"); taskStackBuilder.addNextIntent(mainActivityIntent); title = context.getString(R.string.message_count_notification, messageCount); } else { // same thread, single or multiple messages title = mostRecentNotification.mTitle; BitmapDrawable contactDrawable = (BitmapDrawable) mostRecentNotification.mSender.getAvatar(context, null); if (contactDrawable != null) { // Show the sender's avatar as the big icon. Contact bitmaps are 96x96 so we // have to scale 'em up to 128x128 to fill the whole notification large icon. avatar = contactDrawable.getBitmap(); if (avatar != null) { final int idealIconHeight = res .getDimensionPixelSize(android.R.dimen.notification_large_icon_height); final int idealIconWidth = res .getDimensionPixelSize(android.R.dimen.notification_large_icon_width); if (avatar.getHeight() < idealIconHeight) { // Scale this image to fit the intended size avatar = Bitmap.createScaledBitmap(avatar, idealIconWidth, idealIconHeight, true); } if (avatar != null) { noti.setLargeIcon(avatar); } } } taskStackBuilder.addParentStack(ComposeMessageActivity.class); taskStackBuilder.addNextIntent(mostRecentNotification.mClickIntent); } // TDH Log.d("NotificationDebug", "title: " + title); // Always have to set the small icon or the notification is ignored noti.setSmallIcon(R.drawable.stat_notify_sms); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Update the notification. noti.setContentTitle(title) .setContentIntent(taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); // TDH: Can't do these yet. // .addKind(Notification.KIND_MESSAGE) // .setPriority(Notification.PRIORITY_DEFAULT); // TODO: set based on contact coming // // from a favorite. int defaults = 0; if (isNew) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); String vibrateWhen; if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN)) { vibrateWhen = sp.getString(MessagingPreferenceActivity.NOTIFICATION_VIBRATE_WHEN, null); } else if (sp.contains(MessagingPreferenceActivity.NOTIFICATION_VIBRATE)) { vibrateWhen = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE, false) ? context.getString(R.string.prefDefault_vibrate_true) : context.getString(R.string.prefDefault_vibrate_false); } else { vibrateWhen = context.getString(R.string.prefDefault_vibrateWhen); } boolean vibrateAlways = vibrateWhen.equals("always"); boolean vibrateSilent = vibrateWhen.equals("silent"); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); boolean nowSilent = audioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE; if (vibrateAlways || vibrateSilent && nowSilent) { defaults |= Notification.DEFAULT_VIBRATE; } String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null); noti.setSound(TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr)); if (DEBUG) { Log.d(TAG, "updateNotification: new message, adding sound to the notification"); } } defaults |= Notification.DEFAULT_LIGHTS; noti.setDefaults(defaults); // set up delete intent noti.setDeleteIntent(PendingIntent.getBroadcast(context, 0, sNotificationOnDeleteIntent, 0)); final Notification notification; if (messageCount == 1) { // We've got a single message // TDH Log.d("NotificationDebug", "Single message, with text: " + mostRecentNotification.formatBigMessage(context)); // This sets the text for the collapsed form: noti.setContentText(mostRecentNotification.formatBigMessage(context)); if (mostRecentNotification.mAttachmentBitmap != null) { // The message has a picture, show that notification = new NotificationCompat2.BigPictureStyle(noti) .bigPicture(mostRecentNotification.mAttachmentBitmap) // This sets the text for the expanded picture form: .setSummaryText(mostRecentNotification.formatPictureMessage(context)).build(); } else { // Show a single notification -- big style with the text of the whole message notification = new NotificationCompat2.BigTextStyle(noti) .bigText(mostRecentNotification.formatBigMessage(context)).build(); } } else { // We've got multiple messages if (uniqueThreadCount == 1) { // We've got multiple messages for the same thread. // Starting with the oldest new message, display the full text of each message. // Begin a line for each subsequent message. SpannableStringBuilder buf = new SpannableStringBuilder(); NotificationInfo infos[] = sNotificationSet.toArray(new NotificationInfo[sNotificationSet.size()]); int len = infos.length; for (int i = len - 1; i >= 0; i--) { NotificationInfo info = infos[i]; buf.append(info.formatBigMessage(context)); if (i != 0) { buf.append('\n'); } } noti.setContentText(context.getString(R.string.message_count_notification, messageCount)); // Show a single notification -- big style with the text of all the messages notification = new NotificationCompat2.BigTextStyle(noti).bigText(buf) // Forcibly show the last line, with the app's smallIcon in it, if we // kicked the smallIcon out with an avatar bitmap .setSummaryText((avatar == null) ? null : " ").build(); } else { // Build a set of the most recent notification per threadId. HashSet<Long> uniqueThreads = new HashSet<Long>(sNotificationSet.size()); ArrayList<NotificationInfo> mostRecentNotifPerThread = new ArrayList<NotificationInfo>(); Iterator<NotificationInfo> notifications = sNotificationSet.iterator(); while (notifications.hasNext()) { NotificationInfo notificationInfo = notifications.next(); if (!uniqueThreads.contains(notificationInfo.mThreadId)) { uniqueThreads.add(notificationInfo.mThreadId); mostRecentNotifPerThread.add(notificationInfo); } } // When collapsed, show all the senders like this: // Fred Flinstone, Barry Manilow, Pete... noti.setContentText(formatSenders(context, mostRecentNotifPerThread)); NotificationCompat2.InboxStyle inboxStyle = new NotificationCompat2.InboxStyle(noti); // We have to set the summary text to non-empty so the content text doesn't show // up when expanded. inboxStyle.setSummaryText(" "); // At this point we've got multiple messages in multiple threads. We only // want to show the most recent message per thread, which are in // mostRecentNotifPerThread. int uniqueThreadMessageCount = mostRecentNotifPerThread.size(); int maxMessages = Math.min(MAX_MESSAGES_TO_SHOW, uniqueThreadMessageCount); for (int i = 0; i < maxMessages; i++) { NotificationInfo info = mostRecentNotifPerThread.get(i); inboxStyle.addLine(info.formatInboxMessage(context)); } notification = inboxStyle.build(); if (DEBUG) { Log.d(TAG, "updateNotification: multi messages," + " showing inboxStyle notification"); } } } // TDH Log.d("NotificationDebug", "Showing notification: " + notification); nm.notify(NOTIFICATION_ID, notification); }
From source file:com.xperia64.timidityae.TimidityActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menuBtn1) { switch (mode) { case 0:// ww w . j a v a2s . c om int x = fileFrag.getListView().getFirstVisiblePosition(); fileFrag.getDir(fileFrag.currPath); fileFrag.setSelection(x); break; case 1: if (playFrag != null && !JNIHandler.type) { playFrag.incrementInterface(); } /*else{ Toast.makeText(this, "Non midi file", Toast.LENGTH_SHORT).show(); }*/ break; case 2: int y = plistFrag.getListView().getFirstVisiblePosition(); plistFrag.getPlaylists(plistFrag.mode ? plistFrag.plistName : null); plistFrag.getListView().setSelection(y); break; } } else if (item.getItemId() == R.id.menuBtn2) { switch (mode) { case 0: if (fileFrag != null) fileFrag.getDir(Globals.defaultFolder); break; case 1: if (playFrag != null) { if ((!JNIHandler.type) && Globals.isPlaying == 0) { playFrag.showMidiDialog(); } /*else{ Toast.makeText(this, "Non midi file", Toast.LENGTH_SHORT).show(); }*/ } break; case 2: plistFrag.add(); break; } } else if (item.getItemId() == android.R.id.home) { onBackPressed(); } else if (item.getItemId() == R.id.quit) { deadlyDeath = true; Intent new_intent = new Intent(); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 5); sendBroadcast(new_intent); stopService(new Intent(this, MusicService.class)); unregisterReceiver(activityReceiver); android.os.Process.killProcess(android.os.Process.myPid()); // Probably the same //System.exit(0); } else if (item.getItemId() == R.id.asettings) { Intent mainact = new Intent(this, SettingsActivity.class); mainact.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivityForResult(mainact, 1); } else if (item.getItemId() == R.id.ahelp) { new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.helpt)) .setMessage(getResources().getString(R.string.helper)) .setNegativeButton("OK", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } return super.onOptionsItemSelected(item); }