List of usage examples for android.content Intent removeExtra
public void removeExtra(String name)
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
@Override protected void onResume() { super.onResume(); m_app.getStoredSort();/*from w w w . j a v a2 s . c o m*/ m_app.getStoredFilters(); setFilteredTasks(true); // Select the specified item if one was passed in to this activity // e.g. from the widget Intent intent = this.getIntent(); if (intent.hasExtra(Constants.EXTRA_TASK)) { int position = getPositionFromId(intent.getLongExtra(Constants.EXTRA_TASK, 0)); intent.removeExtra(Constants.EXTRA_TASK); getListView().setItemChecked(position, true); } // Show contextactionbar if there is a selection showContextActionBarIfNeeded(); }
From source file:com.finchuk.clock2.MainActivity.java
/** * Handles a PendingIntent, fired from e.g. clicking a notification, that tells us to * set the ViewPager's current item and scroll to a specific RecyclerView item * given by its stable ID./*from www.j a v a2 s .co m*/ * * @param performScroll Whether to actually scroll to the stable id, if there is one. * Pass true if you know {@link * RecyclerViewFragment#onLoadFinished(Loader, BaseItemCursor) onLoadFinished()} * had previously been called. Otherwise, pass false so that we can * {@link RecyclerViewFragment#setScrollToStableId(long) setScrollToStableId(long)} * and let {@link * RecyclerViewFragment#onLoadFinished(Loader, BaseItemCursor) onLoadFinished()} * perform the scroll for us. */ private void handleActionScrollToStableId(@NonNull final Intent intent, final boolean performScroll) { if (ACTION_SCROLL_TO_STABLE_ID.equals(intent.getAction())) { final int targetPage = intent.getIntExtra(EXTRA_SHOW_PAGE, -1); if (targetPage >= 0 && targetPage <= mSectionsPagerAdapter.getCount() - 1) { // #post() works for any state the app is in, especially robust against // cases when the app was not previously in memory--i.e. this got called // in onCreate(). mViewPager.post(new Runnable() { @Override public void run() { mViewPager.setCurrentItem(targetPage, true/*smoothScroll*/); final long stableId = intent.getLongExtra(EXTRA_SCROLL_TO_STABLE_ID, -1); if (stableId != -1) { RecyclerViewFragment rvFrag = (RecyclerViewFragment) mSectionsPagerAdapter .getFragment(targetPage); if (performScroll) { rvFrag.performScrollToStableId(stableId); } else { rvFrag.setScrollToStableId(stableId); } } intent.setAction(null); intent.removeExtra(EXTRA_SHOW_PAGE); intent.removeExtra(EXTRA_SCROLL_TO_STABLE_ID); } }); } } }
From source file:org.comixwall.pffw.MainActivity.java
public void showFirstFragment() { NavigationView navigationView = findViewById(R.id.navView); Intent intent = getIntent(); Bundle bundle = intent.getExtras();/*from ww w . ja v a 2 s. c o m*/ if (bundle != null && bundle.containsKey("title") && bundle.containsKey("body") && bundle.containsKey("data")) { // If there is a notification bundle, show the notification fragment try { JSONObject data = new JSONObject(bundle.getString("data")); // ATTENTION: Timestamp check is a workaround for the case the user clicks the Overview button // If the activity was created with a notification intent while the app was in the background, // closing the app and then pressing the Overview button recreates the activity with the same intent, // hence we reach here and add the same notification one more time. // Timestamp is a unique notification id to prevent such mistakes // TODO: Find a way to fix this Overview button issue int timestamp = Integer.parseInt(data.getString("timestamp")); if (lastNotificationTimestamp < timestamp) { lastNotificationTimestamp = timestamp; Notifications.addNotification(Notification.newInstance(data)); // Remove one of the extras, so we don't add the same notification again intent.removeExtra("title"); setIntent(new Intent()); } else { Toast.makeText(this, R.string.notification_not_recent, Toast.LENGTH_LONG).show(); logger.finest("showFirstFragment will not process the same or older notification: " + lastNotificationTimestamp); } } catch (Exception e) { logger.warning("showFirstFragment Exception= " + e.getMessage()); } // Reset the fragment, so onNavigationItemSelected() displays the Notifications fragment in any case fragment = new Fragment(); onNavigationItemSelected(navigationView.getMenu().findItem((R.id.menuNotifications))); } else { // Avoid blank pages by showing Dashboard fragment if the backstack is empty if (getSupportFragmentManager().getBackStackEntryCount() == 0) { // Reset the fragment, so onNavigationItemSelected() displays the Dashboard fragment in any case fragment = new Fragment(); onNavigationItemSelected(navigationView.getMenu().findItem(R.id.menuDashboard)); } } createOptionsMenu(); }
From source file:it.feio.android.omninotes.ListFragment.java
/** * Search notes by tags//from w w w . j av a 2s.c om */ private void filterByTags() { // Retrieves all available categories final List<Tag> tags = TagsHelper.getAllTags(); // If there is no category a message will be shown if (tags.size() == 0) { mainActivity.showMessage(R.string.no_tags_created, ONStyle.WARN); return; } // Dialog and events creation new MaterialDialog.Builder(mainActivity).title(R.string.select_tags).items(TagsHelper.getTagsArray(tags)) .positiveText(R.string.ok).itemsCallbackMultiChoice(new Integer[] {}, (dialog, which, text) -> { // Retrieves selected tags List<String> selectedTags = new ArrayList<>(); for (Integer aWhich : which) { selectedTags.add(tags.get(aWhich).getText()); } // Saved here to allow persisting search searchTags = selectedTags.toString().substring(1, selectedTags.toString().length() - 1) .replace(" ", ""); Intent intent = mainActivity.getIntent(); // Hides keyboard searchView.clearFocus(); KeyboardUtils.hideKeyboard(searchView); intent.removeExtra(SearchManager.QUERY); initNotesList(intent); return false; }).build().show(); }
From source file:com.dycody.android.idealnote.ListFragment.java
/** * Search notes by tags/*from w w w. j ava 2s . c o m*/ */ private void filterByTags() { // Retrieves all available categories final List<Tag> tags = TagsHelper.getAllTags(); // If there is no category a message will be shown if (tags.size() == 0) { //mainActivity.showMessage(R.string.no_tags_created, ONStyle.WARN); Toast.makeText(getActivity(), R.string.no_tags_created, Toast.LENGTH_SHORT).show(); return; } // Dialog and events creation new MaterialDialog.Builder(mainActivity).title(R.string.select_tags).items(TagsHelper.getTagsArray(tags)) .positiveText(R.string.ok).itemsCallbackMultiChoice(new Integer[] {}, (dialog, which, text) -> { // Retrieves selected tags List<String> selectedTags = new ArrayList<>(); for (Integer aWhich : which) { selectedTags.add(tags.get(aWhich).getText()); } // Saved here to allow persisting search searchTags = selectedTags.toString().substring(1, selectedTags.toString().length() - 1) .replace(" ", ""); Intent intent = mainActivity.getIntent(); // Hides keyboard searchView.clearFocus(); KeyboardUtils.hideKeyboard(searchView); intent.removeExtra(SearchManager.QUERY); initNotesList(intent); return false; }).build().show(); }
From source file:dk.kk.ibikecphlib.map.MapActivity.java
@SuppressWarnings("deprecation") @Override// ww w.j av a 2s. com public void onResume() { super.onResume(); attemptToRegisterLocationListener(); fromSearch = false; if (!Util.isNetworkConnected(this)) { Util.launchNoConnectionDialog(this); } // TODO: Check if this is even needed as the menu has been added using the fragment manager. leftMenu.onResume(); // Check if the user accepts the newest terms TermsManager.checkTerms(this); // Check if the user was logged out/deleted and spawn a dialog Intent intent = getIntent(); if (intent.hasExtra("loggedOut")) { if (intent.getExtras().getBoolean("loggedOut")) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(IBikeApplication.getString("invalid_token_user_logged_out")); builder.setPositiveButton(IBikeApplication.getString("log_in"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(MapActivity.this, LoginActivity.class); startActivity(intent); dialog.dismiss(); } }); builder.setNegativeButton(IBikeApplication.getString("close"), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.setCancelable(false); builder.show(); } intent.removeExtra("loggedOut"); } else if (intent.hasExtra("deleteUser")) { if (intent.getExtras().getBoolean("deleteUser")) { AlertDialog.Builder builder = new AlertDialog.Builder(MapActivity.this); builder.setMessage(IBikeApplication.getString("account_deleted")); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog dialog = builder.create(); dialog.show(); } intent.removeExtra("deleteUser"); } }
From source file:com.android.deskclock.AlarmClockFragment.java
@Override public void onResume() { super.onResume(); final DeskClock activity = (DeskClock) getActivity(); if (activity.getSelectedTab() == DeskClock.ALARM_TAB_INDEX) { setFabAppearance();/*from w w w . j a va2s . c o m*/ setLeftRightButtonAppearance(); } final int startDay = Utils.getZeroIndexedFirstDayOfWeek(getActivity()); mDayOrder = new int[DaysOfWeek.DAYS_IN_A_WEEK]; for (int i = 0; i < DaysOfWeek.DAYS_IN_A_WEEK; ++i) { mDayOrder[i] = DAY_ORDER[(startDay + i) % 7]; } // Check if another app asked us to create a blank new alarm. final Intent intent = getActivity().getIntent(); if (intent.hasExtra(ALARM_CREATE_NEW_INTENT_EXTRA)) { if (intent.getBooleanExtra(ALARM_CREATE_NEW_INTENT_EXTRA, false)) { // An external app asked us to create a blank alarm. startCreatingAlarm(); } // Remove the CREATE_NEW extra now that we've processed it. intent.removeExtra(ALARM_CREATE_NEW_INTENT_EXTRA); } else if (intent.hasExtra(SCROLL_TO_ALARM_INTENT_EXTRA)) { long alarmId = intent.getLongExtra(SCROLL_TO_ALARM_INTENT_EXTRA, Alarm.INVALID_ID); if (alarmId != Alarm.INVALID_ID) { mScrollToAlarmId = alarmId; if (mCursorLoader != null && mCursorLoader.isStarted()) { // We need to force a reload here to make sure we have the latest view // of the data to scroll to. mCursorLoader.forceLoad(); } } // Remove the SCROLL_TO_ALARM extra now that we've processed it. intent.removeExtra(SCROLL_TO_ALARM_INTENT_EXTRA); } setTimePickerListener(); }
From source file:nuclei.ui.share.PackageTargetManager.java
/** * WeChat and on some android versions Instagram doesn't seem to handle file providers very well, so instead of those we move the * file to external storage and startActivityForResult with the actual file. *//*from w ww. j ava 2s. c o m*/ protected Intent onExternalStorage(Activity activity, String packageName, String authority, Intent intent, int permissionRequestCode, boolean stripText) { if (mFile != null) { if (ContextCompat.checkSelfPermission(activity, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { File file = ShareUtil.newShareFile(new File(Environment.getExternalStorageDirectory(), ".cyto"), mFile.getName()); try { onCopyFile(mFile, file); mFile.delete(); mFile = file; } catch (IOException err) { LOG.e("Error copying file for sharing", err); } onSetFileProvider(activity, packageName, authority, intent); } else { File file = ShareUtil.newShareFile(new File(Environment.getExternalStorageDirectory(), ".cyto"), mFile.getName()); try { onCopyFile(mFile, file); mFile.delete(); mFile = file; } catch (IOException err) { LOG.e("Error copying file for sharing", err); } intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mFile)); } } else { ActivityCompat.requestPermissions(activity, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, permissionRequestCode); return null; } if (stripText && intent.hasExtra(Intent.EXTRA_STREAM) && intent.hasExtra(Intent.EXTRA_TEXT)) intent.removeExtra(Intent.EXTRA_TEXT); } return intent; }
From source file:com.androzic.MapActivity.java
@Override protected void onNewIntent(Intent intent) { Log.e(TAG, "onNewIntent()"); if (intent.hasExtra("launch")) { Serializable object = intent.getExtras().getSerializable("launch"); if (Class.class.isInstance(object)) { Intent launch = new Intent(this, (Class<?>) object); launch.putExtras(intent);// w w w. j a v a 2 s . c om launch.removeExtra("launch"); startActivity(launch); } } else if (intent.hasExtra("lat") && intent.hasExtra("lon")) { Androzic application = (Androzic) getApplication(); application.ensureVisible(intent.getExtras().getDouble("lat"), intent.getExtras().getDouble("lon")); } }