List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK
int FLAG_ACTIVITY_NEW_TASK
To view the source code for android.content Intent FLAG_ACTIVITY_NEW_TASK.
Click Source Link
From source file:com.parse.CN1ParsePushBroadcastReceiver.java
@Override protected void onPushOpen(Context context, Intent intent) { /*//from w w w . jav a2s. co m Adapted from ParsePushBroadcastReceiver. Main changes: 1. Adapted code for starting app activity since it caused problems (see comments towards the end of the method starting from line 'Original code' 2. Implemented necessary ParsePush callback to set push data in advance so that it will be available when the app activity is started/resumed */ // Send a Parse Analytics "push opened" event ParseAnalytics.trackAppOpenedInBackground(intent); JSONObject pushData = null; String uriString = null; try { pushData = new JSONObject(intent.getStringExtra(ParsePushBroadcastReceiver.KEY_PUSH_DATA)); uriString = pushData.optString("uri", null); } catch (JSONException e) { writeErrorLog("Unexpected JSONException when parsing " + "push data from opened notification: " + e); } writeDebugLog("Push opened: " + (pushData == null ? "<no payload>" : pushData.toString())); if (pushData != null) { // Forward payload so that it is available when app is opened via the push message ParsePush.handlePushOpen(pushData.toString(), CN1AndroidApplication.isAppInForeground()); writeDebugLog("Notified ParsePush of opened push notification"); } Class<? extends Activity> cls = getActivity(context, intent); Intent activityIntent; if (uriString != null) { writeDebugLog("Creating an intent to view URI: " + uriString); activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString)); } else { activityIntent = new Intent(context, cls); } activityIntent.putExtras(intent.getExtras()); activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Original code // /* // In order to remove dependency on android-support-library-v4 // The reason why we differentiate between versions instead of just using context.startActivity // for all devices is because in API 11 the recommended conventions for app navigation using // the back key changed. // */ // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // TaskStackBuilderHelper.startActivities(context, cls, activityIntent); // } else { // context.startActivity(activityIntent); // } // The task stack builder approach causes only the title and a white (blank) screen // to be shown when the app is in the foreground and the push notification is // opened (see also problem report to CN1 support forum: https://groups.google.com/d/msg/codenameone-discussions/Z3F924j_BG4/7rn7v7oABwAJ) // As a result, the context.startActivity() approach is currently taken always. // Not sure yet if it has any undesirable side effects for sdk version // before JELLY_BEAN (actually HONEYCOMB (v3.0) according to TaskStackBuilder documentation // at: http://developer.android.com/reference/android/support/v4/app/TaskStackBuilder.html. context.startActivity(activityIntent); }
From source file:com.snappy.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras, String messageData) {//from ww w . j a va2 s.com if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } Log.i(LOG_TAG, message); Log.i(LOG_TAG, fromName); }
From source file:com.shopify.sample.activity.CheckoutActivity.java
private void launchBrowser(String url) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.setData(Uri.parse(url));/*from www . ja v a2 s . c om*/ try { intent.setPackage("com.android.chrome"); startActivity(intent); } catch (Exception launchChromeException) { try { // Chrome could not be opened, attempt to us other launcher intent.setPackage(null); startActivity(intent); } catch (Exception launchOtherException) { onError(getString(R.string.checkout_error)); } } }
From source file:com.nextgis.maplibui.mapui.NGWVectorLayerUI.java
@Override public void showAttributes() { Intent settings = new Intent(mContext, AttributesActivity.class); settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); settings.putExtra(ConstantsUI.KEY_LAYER_ID, getId()); mContext.startActivity(settings);/* w w w .j av a2 s . c o m*/ }
From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java
@SuppressLint({ "NewApi", "SimpleDateFormat" }) public VerticalSingleItemView(final DataMgr dataMgr, final Context context, final String uid, final View menu, final VerticalItemViewCtrl itemViewCtrl) { this.dataMgr = dataMgr; this.context = context; this.item = dataMgr.getItemByUid(uid, ITEM_PROJECTION); this.fontSize = new SettingFontSize(dataMgr).getData(); this.theme = new SettingTheme(dataMgr).getData(); this.showTop = false; this.showBottom = false; this.menu = menu; this.itemViewCtrl = itemViewCtrl; this.imageClickTime = 0; final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.view = inflater.inflate(R.layout.single_item_view, null); // Disable hardware acceleration on Android 3.0-4.1 devices. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); }// www .ja va 2 s.co m lastItemView = view.findViewById(R.id.LastItemView); nextItemView = view.findViewById(R.id.NextItemView); itemScrollView = (OverScrollView) view.findViewById(R.id.ItemScrollView); itemScrollView.setTopScrollView(lastItemView); itemScrollView.setBottomScrollView(nextItemView); itemScrollView.setOnScrollChangeListener(this); itemScrollView.setOnTouchListener(this); final View btnShowOriginal = view.findViewById(R.id.BtnShowOriginal); btnShowOriginal.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { boolean ret = false; final TextView txt = (TextView) view.findViewById(R.id.BtnText); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: txt.setTextColor(0xFF787878); ret = true; break; case MotionEvent.ACTION_MOVE: ret = true; break; case MotionEvent.ACTION_CANCEL: txt.setTextColor(0xBB787878); ret = false; break; case MotionEvent.ACTION_UP: txt.setTextColor(0xBB787878); final SettingBrowserChoice setting = new SettingBrowserChoice(dataMgr); if (setting.getData() == SettingBrowserChoice.BROWSER_CHOICE_EXTERNAL) { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(item.getHref())); context.startActivity(intent); } else if (VerticalSingleItemView.this.listener != null) { VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), false); } break; default: } return ret; } }); final View btnShowMobilized = view.findViewById(R.id.BtnShowMobilized); btnShowMobilized.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent event) { boolean ret = false; final TextView txt = (TextView) view.findViewById(R.id.BtnText); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: txt.setTextColor(0xFF787878); ret = true; break; case MotionEvent.ACTION_MOVE: ret = true; break; case MotionEvent.ACTION_CANCEL: txt.setTextColor(0xBB787878); ret = false; break; case MotionEvent.ACTION_UP: txt.setTextColor(0xBB787878); if (VerticalSingleItemView.this.listener != null) { VerticalSingleItemView.this.listener.showWebsitePage(item.getUid(), true); } ret = true; break; default: } return ret; } }); { final ListItemItem lastItem = itemViewCtrl.getLastItem(item.getUid()); final TextView txt = (TextView) lastItemView.findViewById(R.id.LastItemTitle); txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize); if (lastItem == null) { lastUid = null; menu.findViewById(R.id.BtnPrevious).setEnabled(false); final ImageView img = (ImageView) lastItemView.findViewById(R.id.LastItemArrow); img.setImageResource(R.drawable.no_more_circle); txt.setText(R.string.TxtNoPreviousItem); } else { lastUid = lastItem.getId(); final View btnLast = menu.findViewById(R.id.BtnPrevious); btnLast.setEnabled(true); btnLast.setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { if (listener != null) { listener.showLastItem(); } } }); txt.setText(lastItem.getTitle()); } } { final ListItemItem nextItem = itemViewCtrl.getNextItem(item.getUid()); final TextView txt = (TextView) nextItemView.findViewById(R.id.NextItemTitle); txt.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize); if (nextItem == null) { nextUid = null; menu.findViewById(R.id.BtnNext).setEnabled(false); final ImageView img = (ImageView) nextItemView.findViewById(R.id.NextItemArrow); img.setImageResource(R.drawable.no_more_circle); txt.setText(R.string.TxtNoNextItem); } else { nextUid = nextItem.getId(); final View btnNext = menu.findViewById(R.id.BtnNext); btnNext.setEnabled(true); btnNext.setOnClickListener(new OnClickListener() { @Override public void onClick(final View view) { if (listener != null) { listener.showNextItem(); } } }); txt.setText(nextItem.getTitle()); } } final TextView title = (TextView) view.findViewById(R.id.ItemTitle); title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 3); title.setText(item.getTitle()); final TextView info = (TextView) view.findViewById(R.id.ItemInfo); info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, fontSize * 4 / 5); final StringBuilder infoText = new StringBuilder(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); sdf.setTimeZone(TimeZone.getDefault()); infoText.append(sdf.format(Utils.timestampToDate(item.getTimestamp()))); if (item.getAuthor() != null && item.getAuthor().length() > 0) { infoText.append(" | By "); infoText.append(item.getAuthor()); } if (item.getSourceTitle() != null && item.getSourceTitle().length() > 0) { infoText.append(" ("); infoText.append(item.getSourceTitle()); infoText.append(")"); } info.setText(infoText); webView = (WebView) view.findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.setBackgroundColor(context.getResources() .getColor(theme == SettingTheme.THEME_NORMAL ? R.color.NormalBackground : R.color.DarkBackground)); webView.setFocusable(false); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(final WebView view, final String url) { if (VerticalSingleItemView.this.imageClickTime > System.currentTimeMillis() - 1000) { return true; } final Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(url)); context.startActivity(intent); return true; } }); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsAlert(final WebView view, final String url, final String message, final JsResult result) { if (VerticalSingleItemView.this.listener != null) { if (message.endsWith(".erss")) { VerticalSingleItemView.this.listener .onImageViewRequired(item.getStoragePath() + "/" + message); } else { VerticalSingleItemView.this.listener.onImageViewRequired(message); } } VerticalSingleItemView.this.imageClickTime = System.currentTimeMillis(); result.cancel(); return true; } }); updateButtonStar(); updateButtonSharing(); updateButtonOpenLink(); if (!item.getState().isRead()) { dataMgr.markItemAsReadWithTransactionByUid(uid); NetworkMgr.getInstance().startImmediateItemStateSyncing(); } }
From source file:com.example.android.samplesync.syncadapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w ww .j a v a2 s.com*/ Log.e(TAG, "SyncAdapter==============onPerformSync"); try { // see if we already have a sync-state attached to this account. By // handing // This value to the server, we can just get the contacts that have // been updated on the server-side since our last sync-up long lastSyncMarker = getServerSyncMarker(account); // By default, contacts from a 3rd party provider are hidden in the // contacts // list. So let's set the flag that causes them to be visible, so // that users // can actually see these contacts. if (lastSyncMarker == 0) { ContactManager.setAccountContactsVisibility(getContext(), account, true); } List<RawContact> dirtyContacts; List<RawContact> updatedContacts; // Use the account manager to request the AuthToken we'll need // to talk to our sample server. If we don't have an AuthToken // yet, this could involve a round-trip to the server to request // and AuthToken. final String authtoken = mAccountManager.blockingGetAuthToken(account, Constants.AUTHTOKEN_TYPE, NOTIFY_AUTH_FAILURE); // Make sure that the sample group exists final long groupId = ContactManager.ensureSampleGroupExists(mContext, account); // Find the local 'dirty' contacts that we need to tell the server // about... // Find the local users that need to be sync'd to the server... dirtyContacts = ContactManager.getDirtyContacts(mContext, account); // Send the dirty contacts to the server, and retrieve the // server-side changes updatedContacts = NetworkUtilities.syncContacts(account, authtoken, lastSyncMarker, dirtyContacts); // Update the local contacts database with the changes. // updateContacts() // returns a syncState value that indicates the high-water-mark for // the changes we received. Log.d(TAG, "Calling contactManager's sync contacts"); long newSyncState = ContactManager.updateContacts(mContext, account.name, updatedContacts, groupId, lastSyncMarker); // This is a demo of how you can update IM-style status messages // for contacts on the client. This probably won't apply to // 2-way contact sync providers - it's more likely that one-way // sync providers (IM clients, social networking apps, etc) would // use this feature. ContactManager.updateStatusMessages(mContext, updatedContacts); // Save off the new sync marker. On our next sync, we only want to // receive // contacts that have changed since this sync... setServerSyncMarker(account, newSyncState); if (dirtyContacts.size() > 0) { ContactManager.clearSyncFlags(mContext, dirtyContacts); } } catch (final AuthenticatorException e) { Log.e(TAG, "AuthenticatorException", e); syncResult.stats.numParseExceptions++; } catch (final OperationCanceledException e) { Log.e(TAG, "OperationCanceledExcetpion", e); } catch (final IOException e) { Log.e(TAG, "IOException", e); syncResult.stats.numIoExceptions++; } catch (final AuthenticationException e) { Log.e(TAG, "AuthenticationException", e); syncResult.stats.numAuthExceptions++; } catch (final ParseException e) { Log.e(TAG, "ParseException", e); syncResult.stats.numParseExceptions++; } catch (final JSONException e) { Log.e(TAG, "JSONException", e); syncResult.stats.numParseExceptions++; } // Intent intent = new Intent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(mContext.getApplicationContext(), AuthenticatorActivity.class); mContext.startActivity(intent); }
From source file:foo.fruitfox.evend.LoginActivity.java
public void login(View view) { Intent intent = new Intent(this, WelcomeActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent);/*w w w . j a v a2 s. c om*/ finish(); }
From source file:com.oakesville.mythling.MediaListActivity.java
@Override public void sort() throws IOException, JSONException, ParseException { super.refresh(); getAppSettings().setLastLoad(0);//from w w w . j av a2 s . c o m SortType sortType = getAppSettings().getMediaSettings().getSortType(); if (getMediaType() == MediaType.recordings && (sortType == SortType.byDate || sortType == SortType.byRating)) setPath(""); // recordings list will be flattened Uri uri = new Uri.Builder().path(getPath()).build(); Intent intent = new Intent(Intent.ACTION_VIEW, uri, this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); finish(); }
From source file:com.google.android.testing.nativedriver.server.AndroidNativeDriver.java
/** Start a new activity either in a new task or the current task. */ public void startActivity(Class<?> activityClass) { Intent intent = new Intent(context.getInstrumentation().getContext(), activityClass); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); context.getInstrumentation().startActivitySync(intent); }