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:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void activate(Context context, SignedObj obj) {
    if (!(obj instanceof DbObj)) {
        Log.w(TAG, "Obj not ready yet!");
        return;/* w  w  w  . ja v  a2  s.c o m*/
    }
    if (DBG) {
        JSONObject content = obj.getJson();
        Log.d(TAG, "activating app " + content + " from " + obj.getHash());
    }

    Intent launch = getLaunchIntent(context, (DbObj) obj);
    if (!(context instanceof Activity)) {
        launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }
    context.startActivity(launch);
}

From source file:in.codehex.arrow.LoginActivity.java

/**
 * Authenticates the user. Sends HTTP POST request to the server.
 *//*from w  w  w .  j  a v  a  2s.c  om*/
private void processLogin() {
    showProgressDialog();

    StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.URL_API,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    hideProgressDialog();
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        int error = jsonObject.getInt("error");
                        String message = jsonObject.getString("message");

                        Toast.makeText(LoginActivity.this, message, Toast.LENGTH_SHORT).show();

                        if (error == 0) {
                            SharedPreferences.Editor editor = userPreferences.edit();
                            editor.putString(Config.KEY_PREF_NAME, name);
                            editor.putString(Config.KEY_PREF_PHONE, phone);
                            editor.putString(Config.KEY_PREF_IMEI, imei);
                            editor.apply();

                            intent = new Intent(LoginActivity.this, MainActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hideProgressDialog();
                    Toast.makeText(LoginActivity.this, "Network error! Please check your internet connection!",
                            Toast.LENGTH_SHORT).show();
                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("tag", "user");
            params.put("name", name);
            params.put("imei", imei);
            return params;
        }
    };
    AppController.getInstance().addToRequestQueue(stringRequest, "user");
}

From source file:foam.zizim.android.BoskoiService.java

private void showNotification(String tickerText) {
    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentsTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newBoskoiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis());
    newBoskoiReportNotification.contentIntent = contentIntent;
    newBoskoiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newBoskoiReportNotification.defaults = Notification.DEFAULT_ALL;
    newBoskoiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);
    if (ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newBoskoiReportNotification.sound = ringURI;
    }//w  w  w  .  j  a  va2s  .c  o  m

    if (vibrate) {
        double vibrateLength = 100 * Math.exp(0.53 * 20);
        long[] vibrate = new long[] { 100, 100, (long) vibrateLength };
        newBoskoiReportNotification.vibrate = vibrate;

        if (flashLed) {
            int color = Color.BLUE;
            newBoskoiReportNotification.ledARGB = color;
        }

        newBoskoiReportNotification.ledOffMS = (int) vibrateLength;
        newBoskoiReportNotification.ledOnMS = (int) vibrateLength;
        newBoskoiReportNotification.flags = newBoskoiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS;
    }

    mNotificationManager.notify(NOTIFICATION_ID, newBoskoiReportNotification);
}

From source file:org.wso2.emm.agent.api.ApplicationManager.java

/**
 * Removes an application from the device.
 * @param packageName - Application package name should be passed in as a String.
 *//*from  w ww .  j av  a  2  s  .c  om*/
public void uninstallApplication(String packageName) {
    if (packageName != null
            && !packageName.contains(resources.getString(R.string.application_package_prefix))) {
        packageName = resources.getString(R.string.application_package_prefix) + packageName;
    }

    Uri packageURI = Uri.parse(packageName);
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(uninstallIntent);
}

From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        if (launchedFromShortcut) {
            Intent i = new Intent(this, AppListActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);//from  w  w  w. ja  va2  s  .c  om
        }
        finish();
        return true;
    case R.id.action_fav:
        Utils.setFavorite(packageName, !Utils.isFavorite(packageName, this), this);
        invalidateOptionsMenu();
        break;
    case R.id.action_shortcut:
        createShortcut();
        Toast.makeText(this, R.string.toast_shortcut, Toast.LENGTH_SHORT).show();
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.cts.browser.BrowserBenchTest.java

private void doTest(String url, ResultType typeNonFinal, ResultUnit unitNonFinal, ResultType typeFinal,
        ResultUnit unitFinal, int numberRepeat) throws InterruptedException {
    mTypeNonFinal = typeNonFinal;// w w  w . j  a  v a  2 s  .c  om
    mUnitNonFinal = unitNonFinal;
    mTypeFinal = typeFinal;
    mUnitFinal = unitFinal;
    mNumberRepeat = numberRepeat;
    Uri uri = Uri.parse(url);
    for (mRunIndex = 0; mRunIndex < numberRepeat; mRunIndex++) {
        Log.i(TAG, mRunIndex + "-th round");
        mLatch = new CountDownLatch(1);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        // force using only one window or tab
        intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
        getContext().startActivity(intent);
        boolean ok = mLatch.await(BROWSER_COMPLETION_TIMEOUT_IN_MS, TimeUnit.MILLISECONDS);
        assertTrue("timed-out", ok);
    }
    // it is somewhat awkward to handle the last one specially with Map
    int numberEntries = mResultsMap.size();
    int numberToProcess = 1;
    for (Map.Entry<String, double[]> entry : mResultsMap.entrySet()) {
        String message = entry.getKey();
        double[] scores = entry.getValue();
        if (numberToProcess == numberEntries) { // final score
            // store the whole results first
            getReportLog().printArray(message, scores, mTypeFinal, mUnitFinal);
            getReportLog().printSummary(message, Stat.getAverage(scores), mTypeFinal, mUnitFinal);
        } else { // interim results
            getReportLog().printArray(message, scores, mTypeNonFinal, mUnitNonFinal);
        }
        numberToProcess++;
    }
}

From source file:fr.free.nrw.commons.Utils.java

/**
 * Opens Custom Tab Activity with in-app browser for the specified URL.
 * Launches intent for web URL//w w w .  j  ava 2s  .  c  om
 * @param context
 * @param url
 */
public static void handleWebUrl(Context context, Uri url) {
    Timber.d("Launching web url %s", url.toString());
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
    if (browserIntent.resolveActivity(context.getPackageManager()) == null) {
        Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT);
        toast.show();
        return;
    }

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor));
    builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
    builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    CustomTabsIntent customTabsIntent = builder.build();
    // Clear previous browser tasks, so that back/exit buttons work as intended.
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    customTabsIntent.launchUrl(context, url);
}

From source file:com.dcs.fakecurrencydetector.MainActivity.java

public void AppExit() {

    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/* w  w w  .jav  a  2 s.c  o  m*/

    /*int pid = android.os.Process.myPid();=====> use this if you want to kill your activity. But its not a good one to do.
    android.os.Process.killProcess(pid);*/

}

From source file:jieehd.villain.updater.VillainUpdater.java

private boolean haveNetworkConnection() {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;

    }//from  w ww.j  a v a  2  s.c  om
    if (haveConnectedWifi == false && haveConnectedMobile == false) {
        Log.d("Network State", "false");
        AlertDialog.Builder alert = new AlertDialog.Builder(VillainUpdater.this);
        alert.setTitle("No Data Connection!");
        alert.setMessage(
                "You have no data connection, click ok to turn on WiFi or Mobile Data in order to check for OTA updates.");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                // TODO Auto-generated method stub
                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);
            }

        });
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                return;
            }
        });
        alert.show();

    } else {
        download();
    }
    return haveConnectedWifi || haveConnectedMobile;
}

From source file:de.madvertise.android.sdk.Ad.java

/**
 * Handles the click action (opens the click url)
 *///from   ww  w.  j av a 2 s .com
protected void handleClick() {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(clickURL));
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {
        context.startActivity(intent);
    } catch (Exception e) {
        MadUtil.logMessage(null, Log.DEBUG, "Failed to open URL : " + clickURL);
        e.printStackTrace();
    }
}