Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

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

Click Source Link

Usage

From source file:com.krayzk9s.imgurholo.services.UploadService.java

public void onGetObject(Object o, String tag) {
    String id = (String) o;
    if (id.length() == 7) {
        if (totalUpload != -1)
            ids.add(id);//from w w  w  .j  a v a 2 s  . c  om
        if (ids.size() == totalUpload) {
            ids.add(0, ""); //weird hack because imgur eats the first item of the array for some bizarre reason
            NewAlbumAsync newAlbumAsync = new NewAlbumAsync("", "", apiCall, ids, this);
            newAlbumAsync.execute();
        }
    } else if (apiCall.settings.getBoolean("AlbumUpload", true)) {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Intent viewImageIntent = new Intent();
        viewImageIntent.setAction(Intent.ACTION_VIEW);
        viewImageIntent.setData(Uri.parse("http://imgur.com/a/" + id));
        Intent shareIntent = new Intent();
        shareIntent.setType("text/plain");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        shareIntent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + id);
        PendingIntent viewImagePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                viewImageIntent, 0);
        PendingIntent sharePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                shareIntent, 0);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading Album").setContentTitle("imgur Image Uploader")
                .setContentIntent(viewImagePendingIntent)
                .addAction(R.drawable.dark_social_share, "Share", sharePendingIntent).build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    } else {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading All Images").setContentTitle("imgur Image Uploader")
                .build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    }
}

From source file:com.btmura.android.reddit.app.GlobalMenuFragment.java

public boolean onQueryTextSubmit(String query) {
    if (listener != null && listener.submitQuery(query)) {
        searchItem.collapseActionView();
    } else {//ww  w  .  ja  v  a 2  s  .c o m
        Intent intent = new Intent(getActivity(), SearchActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.putExtra(SearchActivity.EXTRA_SUBREDDIT, subredditNameHolder.getSubreddit());
        intent.putExtra(SearchActivity.EXTRA_QUERY, query);
        startActivityForResult(intent, REQUEST_SEARCH);
    }
    return true;
}

From source file:com.avalon.share.ShareHelper.java

public static void shareString(String text) {
    // create an intent, so the user can choose which application he/she wants to use to share this file
    final Intent intent = ShareCompat.IntentBuilder.from(activity).setType("text/plain").setText(text)
            //.setChooserTitle(R.string.share_title)
            .createChooserIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

    activity.startActivity(intent);//  ww w.  j a va 2s . co  m
}

From source file:org.xbmc.kore.utils.Utils.java

/**
 * Open the IMDb app or web page for the given person name.
 *///w w w.  ja v a2s . c  o m
public static void openImdbForMovie(Context context, String imdbNumber) {
    if (context == null || TextUtils.isEmpty(imdbNumber)) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(IMDB_APP_MOVIE_URI, imdbNumber)));
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    // try launching IMDb app
    if (!Utils.tryStartActivity(context, intent)) {
        // on failure, try launching the web page
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(IMDB_MOVIE_URL, imdbNumber)));
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        context.startActivity(intent);
    }
}

From source file:com.udacity.sunshine.fragment.DetailFragment.java

private Intent createShareForecastIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mForecastStr + FORECAST_SHARE_HASHTAG);
    return shareIntent;
}

From source file:com.krayzk9s.imgurholo.services.DownloadService.java

@Override
protected void onHandleIntent(Intent intent) {
    final NotificationManager notificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    ids = intent.getParcelableArrayListExtra("ids");
    albumName = "/";
    downloaded = 0;/* w w w.  j  a va 2 s. c o  m*/
    if (ids.size() > 0) {
        albumName += intent.getStringExtra("albumName") + "/";
        File myDirectory = new File(
                android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                albumName);
        if (!myDirectory.exists()) {
            myDirectory.mkdirs();
        }
    }
    for (int i = 0; i < ids.size(); i++) {
        try {
            final String type = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE)
                    .split("/")[1];
            final String id = ids.get(i).getJSONObject().getString("id");
            final String link = ids.get(i).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK);
            Log.d("data", ids.get(i).getJSONObject().toString());
            Log.d(ImgurHoloActivity.IMAGE_DATA_TYPE,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE).split("/")[1]);
            Log.d("id", ids.get(i).getJSONObject().getString("id"));
            Log.d(ImgurHoloActivity.IMAGE_DATA_LINK,
                    ids.get(0).getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_LINK));
            final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
            notificationBuilder.setContentTitle(getString(R.string.picture_download))
                    .setContentText(getString(R.string.download_in_progress))
                    .setSmallIcon(R.drawable.icon_desaturated);
            Ion.with(getApplicationContext(), link).progress(new ProgressCallback() {
                @Override
                public void onProgress(int i, int i2) {
                    notificationBuilder.setProgress(i2, i, false);
                }
            }).write(new File(
                    android.os.Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
                            + albumName + id + "." + type))
                    .setCallback(new FutureCallback<File>() {
                        @Override
                        public void onCompleted(Exception e, File file) {
                            if (file == null)
                                return;
                            downloaded += 1;
                            if (downloaded == ids.size()) {
                                NotificationCompat.Builder notificationComplete = new NotificationCompat.Builder(
                                        getApplicationContext());
                                if (ids.size() == 1) {
                                    Intent viewImageIntent = new Intent(Intent.ACTION_VIEW);
                                    viewImageIntent.setDataAndType(Uri.fromFile(file), "image/*");
                                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                                    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                                    shareIntent.setType("image/*");
                                    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            viewImageIntent, 0);
                                    PendingIntent sharePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(),
                                            shareIntent, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated)
                                            .setContentText(String.format(getString(R.string.download_progress),
                                                    downloaded))
                                            .setContentIntent(viewImagePendingIntent)
                                            .addAction(R.drawable.dark_social_share, getString(R.string.share),
                                                    sharePendingIntent);
                                } else {
                                    Intent i = new Intent(Intent.ACTION_PICK);
                                    i.setDataAndType(
                                            Uri.fromFile(new File(
                                                    android.os.Environment.getExternalStoragePublicDirectory(
                                                            Environment.DIRECTORY_PICTURES) + albumName)),
                                            "image/*");
                                    PendingIntent viewImagePendingIntent = PendingIntent.getActivity(
                                            getApplicationContext(), (int) System.currentTimeMillis(), i, 0);
                                    notificationComplete.setContentTitle(getString(R.string.download_complete))
                                            .setSmallIcon(R.drawable.icon_desaturated).setContentText(String
                                                    .format(getString(R.string.download_progress), downloaded))
                                            .setContentIntent(viewImagePendingIntent);
                                }
                                notificationManager.cancel(0);
                                notificationManager.cancel(1);
                                notificationManager.notify(1, notificationComplete.build());
                            }
                            MediaScannerConnection.scanFile(getApplicationContext(),
                                    new String[] { android.os.Environment.getExternalStoragePublicDirectory(
                                            Environment.DIRECTORY_PICTURES) + albumName + id + "." + type },
                                    null, new MediaScannerConnection.OnScanCompletedListener() {
                                        @Override
                                        public void onScanCompleted(final String path, final Uri uri) {
                                            Log.i("Scanning", String.format("Scanned path %s -> URI = %s", path,
                                                    uri.toString()));
                                        }
                                    });
                        }
                    });
            notificationManager.notify(0, notificationBuilder.build());
        } catch (JSONException e) {
            Log.e("Error!", e.toString());
        }
    }
}

From source file:com.conferenceengineer.android.iosched.ui.AnnouncementsFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (mCursor == null) {
        return;/*from   w ww.  j a  v a2 s . com*/
    }

    mCursor.moveToPosition(position);
    String url = mCursor.getString(AnnouncementsQuery.ANNOUNCEMENT_URL);
    Intent postDetailIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    postDetailIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    UIUtils.preferPackageForIntent(getActivity(), postDetailIntent, UIUtils.TWITTER_PACKAGE_NAME);
    startActivity(postDetailIntent);
}

From source file:com.jbirdvegas.mgerrit.cards.PatchSetPropertiesCard.java

private void setClicksToActionViews(Cursor cursor, ImageView share, ImageView browser) {

    String webAddress = getWebAddress(cursor.getString(changenum_index));

    share.setTag(R.id.webAddress, webAddress);
    share.setTag(R.id.changeID, cursor.getString(changeid_index));
    browser.setTag(R.id.webAddress, webAddress);

    share.setOnClickListener(new View.OnClickListener() {
        @Override//w  w  w.j a v  a 2 s.  c  o m
        public void onClick(View view) {
            String changeId = (String) view.getTag(R.id.changeID);
            String webAddress = (String) view.getTag(R.id.webAddress);

            Intent intent = new Intent(android.content.Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            intent.putExtra(Intent.EXTRA_SUBJECT,
                    String.format(view.getContext().getString(R.string.commit_shared_from_mgerrit), changeId));
            intent.putExtra(Intent.EXTRA_TEXT, webAddress + " #mGerrit");
            view.getContext().startActivity(intent);
        }
    });
    browser.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String webAddress = (String) view.getTag(R.id.webAddress);

            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webAddress));
            view.getContext().startActivity(browserIntent);
        }
    });
}

From source file:inforuh.eventfinder.ui.DetailActivity.java

private Intent createShareIntent(String message) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_TEXT, message);
    return intent;
}

From source file:com.developers.pnp.lilly.app.DetailFragment.java

private Intent createSharePlacetIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT, mPlace + PLACE_SHARE_HASHTAG);
    return shareIntent;
}