Example usage for android.content Intent FLAG_ACTIVITY_NEW_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_NEW_TASK

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

Click Source Link

Document

If set, this activity will become the start of a new task on this history stack.

Usage

From source file:com.adguard.android.commons.BrowserUtils.java

public static void openYandexBlockingOptions(Context context) {
    Intent intent = new Intent();
    intent.setAction(YANDEX_CONTENT_BLOCKER_ACTION);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {
        context.startActivity(intent);/*from  www  . j  a v  a  2 s.c  o m*/
        return;
    }

    // For samsung-type action in Yandex browser
    intent.setAction(SAMSUNG_CONTENT_BLOCKER_ACTION);
    list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (list.size() > 0) {

        ComponentName componentName = getYandexBrowser(context, SAMSUNG_CONTENT_BLOCKER_ACTION);
        if (componentName != null) {
            intent.setClassName(componentName.getPackageName(), componentName.getClassName());
        }

        context.startActivity(intent);
    }
}

From source file:com.oakesville.mythling.MainActivity.java

public void onBackPressed() {
    if (EpgActivity.class.getName().equals(backTo) || FireTvEpgActivity.class.getName().equals(backTo)) {
        Intent a = new Intent(Intent.ACTION_MAIN);
        a.addCategory(Intent.CATEGORY_HOME);
        a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(a);//from ww w.  j a  v  a2s .  c o  m
    } else {
        super.onBackPressed();
    }
}

From source file:com.kakao.kakaolink.KakaoLink.java

/**
 *  ? ??    ./*from  w ww. j  av  a2  s.  c o  m*/
 * @param builder     KakaoTalkLinkMessageBuilder
 * @param context ?  context
 * @throws KakaoParameterException ?   ?   ? ?
 */
public void sendMessage(final KakaoTalkLinkMessageBuilder builder, final Context context)
        throws KakaoParameterException {
    final Intent intent = TalkProtocol.createKakakoTalkLinkIntent(context, builder.build());
    if (intent == null) {
        //alert install dialog
        new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_dialog_alert)
                .setMessage(context.getString(R.string.com_kakao_alert_install_kakaotalk))
                .setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent marketIntent;
                        try {
                            marketIntent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(KakaoTalkLinkProtocol.TALK_MARKET_URL_PREFIX + makeReferrer()));
                            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(marketIntent);
                        } catch (ActivityNotFoundException e) {
                            marketIntent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(KakaoTalkLinkProtocol.TALK_MARKET_URL_PREFIX_2 + makeReferrer()));
                            marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(marketIntent);
                        }
                    }
                }).create().show();

    } else {
        context.startActivity(intent);
    }
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override/*from w w  w  . jav  a 2  s .  co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:org.roman.findme.MyGcmListenerService.java

void displayMessage(String message) {
    if (MessageActivity.active) {
        MessageActivity.addSenderMessage(message);
    } else {/*from  w ww  .  j a  v  a  2 s  .c  om*/
        Intent intent = new Intent(this, MessageActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("message", message);
        startActivity(intent);
    }

}

From source file:com.alphabetbloc.accessmrs.services.SyncAdapter.java

private void performSync(SyncResult syncResult) {
    mTimeoutException = null;// w w w .  j av a2 s .c o m
    HttpClient client = NetworkUtils.getHttpClient();
    if (client == null) {
        // ++syncResult.stats.numIoExceptions;
        Log.e(TAG, "HttpClient is null!  Check the credential storage!");
        Intent i = new Intent(mContext, LauncherActivity.class);
        i.putExtra(LauncherActivity.LAUNCH_DASHBOARD, false);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
        UiUtils.toastAlert(mContext.getString(R.string.sync_error), mContext.getString(R.string.no_connection));
        return;
    }
    // UPLOAD FORMS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms), false); // 0%
    String[] instancesToUpload = mSyncManager.getInstancesToUpload();
    String[] instancesUploaded = uploadInstances(client, instancesToUpload, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms),
            (instancesUploaded.length < 1) ? true : false); // 10%
    String dbError = mSyncManager.updateUploadedForms(instancesUploaded, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms),
            (instancesUploaded.length < 1) ? true : false); // 20%
    int uploadErrors = (int) syncResult.stats.numIoExceptions;
    mSyncManager.toastSyncUpdate(SyncManager.UPLOAD_FORMS, instancesUploaded.length, instancesToUpload.length,
            uploadErrors, dbError);
    if (App.DEBUG)
        Log.v(TAG, "End of Upload ConnectionTimeOutException=" + mTimeoutException);
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }

    // DOWNLOAD NEW FORMS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms), false); // No
    // Change
    Form[] formsToDownload = findNewFormsOnServer(client, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsToDownload.length < 1) ? true : false); // 30%
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }
    Form[] formsDownloaded = downloadNewForms(client, formsToDownload, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsDownloaded.length < 1) ? true : false); // 40%
    dbError = mSyncManager.updateDownloadedForms(formsDownloaded, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsDownloaded.length < 1) ? true : false); // 50%
    if (App.DEBUG)
        Log.v(TAG, "Downloaded New Forms with result errors=" + syncResult.stats.numIoExceptions);
    int downloadErrors = ((int) syncResult.stats.numIoExceptions) - uploadErrors;
    mSyncManager.toastSyncUpdate(SyncManager.DOWNLOAD_FORMS, formsDownloaded.length, formsToDownload.length,
            downloadErrors, dbError);
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }

    // DOWNLOAD NEW OBS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_data), false); // No
    // Change
    long before = System.currentTimeMillis();
    File temp = downloadObsStream(client, syncResult);
    if (App.DEBUG)
        Log.v("SYNC BENCHMARK",
                "Download Time: \n" + sTimeLog.format(new Date(System.currentTimeMillis() - before)));
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_updating_data), true); // 60%
    if (temp != null) {
        dbError = mSyncManager.readObsFile(temp, syncResult); // 70-100%
        FileUtils.deleteFile(temp.getAbsolutePath());
    }
    int downloadObsErrors = ((int) syncResult.stats.numIoExceptions) - (uploadErrors + downloadErrors);
    mSyncManager.toastSyncUpdate(SyncManager.DOWNLOAD_OBS, -1, -1, downloadObsErrors, dbError);
    if (App.DEBUG)
        Log.v(TAG, "Downloaded New Obs with result errors=" + syncResult.stats.numIoExceptions);

    // TOAST RESULT
    mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, null);

}

From source file:in.codehex.facilis.ForgotPasswordActivity.java

/**
 * Send request to the server to reset the password of the user.
 *
 * @param email the email address of the user.
 *//*from w  w w  .  j a v  a2  s  .com*/
private void processForgotPass(String email) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put(Config.KEY_API_EMAIL, email);
    } catch (JSONException e) {
        // TODO: remove toast
        Toast.makeText(ForgotPasswordActivity.this, "Error occurred while generating data - " + e.getMessage(),
                Toast.LENGTH_SHORT).show();
    }

    showProgressDialog();
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Config.API_FORGOT_PASS,
            jsonObject, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    hideProgressDialog();
                    mIntent = new Intent(ForgotPasswordActivity.this, LoginActivity.class);
                    mIntent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(mIntent);
                    Toast.makeText(ForgotPasswordActivity.this,
                            "Password reset link has been sent to your mail", Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hideProgressDialog();
                    NetworkResponse response = error.networkResponse;
                    // TODO: remove toast
                    if (response.statusCode == 400)
                        Toast.makeText(ForgotPasswordActivity.this,
                                "Error processing your request! Try again later!", Toast.LENGTH_SHORT).show();
                }
            });

    AppController.getInstance().addToRequestQueue(jsonObjectRequest, "forgot_pass");
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java

@Override
public void activate(Context context, SignedObj obj) {
    JSONObject content = obj.getJson();//from w w w  .  j  a  va2 s. c o  m
    if (content.has(URL)) {
        Intent view = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(content.optString(URL));
        String type = "audio/x-mpegurl";
        if (content.has(MIME_TYPE)) {
            type = content.optString(MIME_TYPE);
        }
        view.setDataAndType(uri, type);
        if (!(context instanceof Activity)) {
            view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(view);
    }
}

From source file:gov.nasa.arc.geocam.talk.UIUtils.java

/**
 * Go to the {@link SettingsActivity} activity.
 *
 * @param context the context/*from  w  ww .j  ava2 s .co  m*/
 */
public static void goToSettings(Context context) {
    final Intent intent = new Intent(context, SettingsActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:me.kartikarora.transfersh.adapters.FileGridAdapter.java

@Override
public void bindView(View view, final Context context, Cursor cursor) {
    FileItemViewHolder holder = (FileItemViewHolder) view.getTag();
    int nameCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_NAME);
    int typeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_TYPE);
    int sizeCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_SIZE);
    int urlCol = cursor.getColumnIndex(FilesContract.FilesEntry.COLUMN_URL);
    final String name = cursor.getString(nameCol);
    final String type = cursor.getString(typeCol);
    final String size = cursor.getString(sizeCol);
    final String url = cursor.getString(urlCol);
    holder.fileNameTextView.setText(name);
    String ext = FilenameUtils.getExtension(name);
    int identifier = context.getResources().getIdentifier("t" + ext, "drawable", context.getPackageName());
    try {/*from   ww  w.  j a va 2 s .  c o m*/
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), identifier, null));
    } catch (Resources.NotFoundException e) {
        e.printStackTrace();
        holder.fileTypeImageView
                .setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.tblank, null));
    }

    holder.fileInfoImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String message = "Name: " + name + "\n" + "File type: " + type + "\n" + "URL: " + url;
            new AlertDialog.Builder(activity).setMessage(message).setPositiveButton(android.R.string.ok, null)
                    .create().show();
        }
    });

    holder.fileShareImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tracker.send(
                    new HitBuilders.EventBuilder().setCategory("Action").setAction("Share : " + url).build());
            context.startActivity(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, url)
                    .setType("text/plain").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }
    });

    holder.fileDownloadImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            checkForDownload(name, type, url, view);
        }
    });
}