Example usage for android.content Intent FLAG_ACTIVITY_NO_HISTORY

List of usage examples for android.content Intent FLAG_ACTIVITY_NO_HISTORY

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_NO_HISTORY.

Prototype

int FLAG_ACTIVITY_NO_HISTORY

To view the source code for android.content Intent FLAG_ACTIVITY_NO_HISTORY.

Click Source Link

Document

If set, the new activity is not kept in the history stack.

Usage

From source file:com.trail.octo.UploadDocs.java

public boolean askCameraPermission() {
    check = false;/*w w  w .  j  av  a2  s .  co m*/
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(UploadDocs.this,
            Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(UploadDocs.this, Manifest.permission.CAMERA)) {
            Log.e("Permission", "Explain here");
            Toast.makeText(getApplicationContext(), "OCTO requires this Permission to upload Images!",
                    Toast.LENGTH_LONG).show();
            final Intent i = new Intent();
            i.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            i.addCategory(Intent.CATEGORY_DEFAULT);
            i.setData(Uri.parse("package:" + UploadDocs.this.getPackageName()));
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            startActivity(i);

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.

        } else {

            // No explanation needed, we can request the permission.
            Log.e("Permission", "Requesting");
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA },
                    PERMISSION_REQUEST_CAMERA);
            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
        return true;
    }
    return check;
}

From source file:fm.smart.r1.activity.ItemActivity.java

@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it/*from  w w w . ja  v a  2s .co  m*/
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (Main.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.item_node.atts.get("id"));
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = addItemToList(Main.default_study_list_id,
                            (String) item.item_node.atts.get("id"), ItemActivity.this);
                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default list

                        ItemActivity.add_sentence_list_result = addSentenceToList(sentence_id,
                                (String) item.item_node.atts.get("id"), Main.default_study_list_id,
                                ItemActivity.this);
                        result = ItemActivity.add_sentence_list_result;
                        if (ItemActivity.add_sentence_list_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.item_node.atts.get("id"),
                                    Main.default_study_list_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this,
                                                item.item_node.atts.get("id").toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:com.trail.octo.UploadDocs.java

public boolean askGalleryPermission() {
    check = false;/*from w w  w. ja v  a  2  s. c  om*/
    // Here, thisActivity is the current activity
    if (ContextCompat.checkSelfPermission(UploadDocs.this,
            Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(UploadDocs.this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {
            Log.e("Permission", "Explain here");
            Toast.makeText(getApplicationContext(), "OCTO requires this Permission to upload Images!",
                    Toast.LENGTH_LONG).show();
            final Intent i = new Intent();
            i.setAction(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            i.addCategory(Intent.CATEGORY_DEFAULT);
            i.setData(Uri.parse("package:" + UploadDocs.this.getPackageName()));
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            i.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            startActivity(i);
            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
        } else {

            // No explanation needed, we can request the permission.
            Log.e("Permission", "Requesting");
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    PERMISSION_REQUEST_READ_EXTERAL_STORAGE);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {
        return true;
    }
    return check;
}

From source file:com.moro.synapsemod.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle != null && mDrawerToggle.onOptionsItemSelected(item))
        return true;

    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_apply:
        ActionValueUpdater.applyElements();
        return true;
    case R.id.action_cancel:
        ActionValueUpdater.cancelElements();
        return true;
    //case R.id.action_select_multi:
    //   startActionMode(ElementSelector.callback);
    //   return true;
    case R.id.action_settings:
        Intent intent = new Intent(this, Settings.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        this.startActivity(intent);
        return true;
    case R.id.menu_backup:
        guardar_perfil();/*from   w w  w  . ja  v  a 2  s  . c  o  m*/
        return true;
    case R.id.menu_restore:
        dialogo_restaurar();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:de.tap.easy_xkcd.utils.PrefHelper.java

public void showRateSnackbar(final String packageName, final Context context, FloatingActionButton mFab) {
    // Thanks to /u/underhound for this great idea! https://www.reddit.com/r/Android/comments/3i6uw0/dev_i_think_ive_mastered_the_art_of_asking_for/
    if (showRateDialog()) {
        View.OnClickListener oc = new View.OnClickListener() {
            @Override/*from   w ww.j  av a 2 s.co  m*/
            public void onClick(View v) {
                Uri uri = Uri.parse("market://details?id=" + packageName);
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                SharedPreferences.Editor editor = sharedPrefs.edit();
                editor.putInt(RATE_SNACKBAR, 32);
                editor.apply();
                try {
                    context.startActivity(intent);
                } catch (ActivityNotFoundException e) {
                    context.startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://play.google.com/store/apps/details?id=" + packageName)));
                }
            }
        };
        Snackbar.make(mFab, R.string.snackbar_rate, Snackbar.LENGTH_LONG)
                .setAction(R.string.snackbar_rate_action, oc).show();
    }
}

From source file:abanoubm.dayra.main.Main.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == FOLDER_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*");
            startActivity(intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
        }/*from w w w.j  a  v a 2  s. c om*/

    } else if (requestCode == IMPORT_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
            importDB();

    }
}

From source file:org.puder.trs80.MainActivity.java

private void showRating() {
    Uri uri = Uri.parse("market://details?id=" + getPackageName());
    Intent playMarketIntent = new Intent(Intent.ACTION_VIEW, uri);
    playMarketIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT
            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    try {/*from ww  w  .j a v a  2 s.c  o  m*/
        startActivity(playMarketIntent);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
    }
}

From source file:net.henryco.opalette.application.StartUpActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.startMenuAbout: {
        String appVersion = GodConfig.JSON_CONF.APP_NAME + " v" + GodConfig.JSON_CONF.APP_VERSION_NUMB + " "
                + GodConfig.JSON_CONF.APP_VERSION_TAG + ".";
        String about = "\n\n" + Utils.getSourceAssetsText(GodConfig.DEF_ABOUT_FILE, this);
        String mails = "";
        for (String s : GodConfig.JSON_CONF.APP_DEV_MAILS)
            mails += "\n" + s;
        for (String s : GodConfig.JSON_CONF.APP_OTHER_MAILS)
            mails += "\n" + s;

        new OPallAlertDialog().title(getResources().getString(R.string.about))
                .message(appVersion + about + mails).positive(getResources().getString(R.string.close))
                .show(getSupportFragmentManager(), "About dialog");
        return true;
    }/* w  w w.j a  v  a2s .  c o m*/

    case R.id.startMenuRate: {
        Uri uri = Uri.parse("market://details?id=" + getPackageName());
        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
        int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
        if (Build.VERSION.SDK_INT >= 21)
            flags |= Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
        else
            flags |= Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET;
        goToMarket.addFlags(flags);
        try {
            startActivity(goToMarket);
        } catch (ActivityNotFoundException e) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://play.google.com/store/apps/details?id=" + getPackageName())));
        }
        return true;
    }

    case R.id.startMenuSettings: {
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsIntent);
        return true;
    }

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.kiwix.kiwixmobile.KiwixMobileActivity.java

private void goToRateApp() {

    Intent goToMarket = new Intent(Intent.ACTION_VIEW, KIWIX_LOCAL_MARKET_URI);

    goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
            | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

    try {/*from w w w.  ja v  a 2s  .  c o m*/
        startActivity(goToMarket);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW, KIWIX_BROWSER_MARKET_URI));
    }
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

private void updateContent(int selection) {
    if (selection != oldSelection) {
        Bundle bundle = new Bundle();
        bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId());

        String className = classes.get(selection);

        if (className.equals("com.abewy.android.apps.klyph.fragment.Chat")) {
            PackageManager pm = getPackageManager();

            try {
                pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES);
                Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME);
                startActivity(intent);//from   www  .  ja v  a  2s  .c  o m
            } catch (NameNotFoundException e) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI));
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                startActivity(intent);
            }
        } else {
            if (selection < navAdapter.getCount())
                setTitle(navAdapter.getItem(selection));
            else
                setTitle(KlyphSession.getSessionUserName());

            Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle);

            if (previousFragment != null)
                previousFragment.onSetToBack(this);

            FragmentTransaction tx = getFragmentManager().beginTransaction();

            tx.replace(R.id.main, fragment, FRAGMENT_TAG);
            tx.commitAllowingStateLoss();
            ((IKlyphFragment) fragment).onSetToFront(this);

            previousFragment = (IKlyphFragment) fragment;

            navAdapter.setSelectedPosition(selection);
            navAdapter.notifyDataSetChanged();

            oldSelection = selection;

            if (notificationsFragment != null)
                notificationsFragment.setHasOptionsMenu(false);
        }
    }
}