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:id.zelory.tanipedia.activity.BeritaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_berita);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);

    setSupportActionBar(toolbar);/*  w  w  w .  j  a  v a  2s .  c  om*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Berita Terbaru");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(1).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(BeritaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                return true;
            case R.id.tanya:
                intent = new Intent(BeritaActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                intent = new Intent(BeritaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(BeritaActivity.this, "nama", null);
                intent = new Intent(BeritaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(BeritaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });
    imageHeader = (ImageView) findViewById(R.id.header);
    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private Intent getLaunchIntent(Context context, String url, String title, String sel) {
    Intent intent = null;/*from  w w  w  .  ja va 2  s  .  co  m*/
    String number = parseTelephoneNumber(sel);
    if (number != null) {
        intent = new Intent("android.intent.action.DIAL", Uri.parse("tel:" + number));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        cm.setText(number);
    } else if (sel != null && sel.length() > 0) {
        // No intent for selection - just copy to clipboard
        ClipboardManager cm = (ClipboardManager) context.getSystemService(CLIPBOARD_SERVICE);
        cm.setText(sel);
    } else {
        final String GMM_PACKAGE_NAME = "com.google.android.apps.maps";
        final String GMM_CLASS_NAME = "com.google.android.maps.MapsActivity";

        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (isMapsURL(url)) {
            intent.setClassName(GMM_PACKAGE_NAME, GMM_CLASS_NAME);
        }

        // Fall back if we can't resolve intent (i.e. app missing)
        PackageManager pm = context.getPackageManager();
        if (null == intent.resolveActivity(pm)) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
    }
    return intent;
}

From source file:kaist.cs492c_2015.washerbrowser.MyGcmListenerService.java

private void launchPopupActivity(Context context, String datavalue) {
    Intent pupInt = new Intent(context, ShowPopup.class);
    pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pupInt.putExtra("customdata", datavalue);
    context.getApplicationContext().startActivity(pupInt);
}

From source file:com.arthackday.killerapp.GCMIntentService.java

@Override
protected void onMessage(Context ctxt, Intent message) {
    Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh GCMessage");
    Bundle extras = message.getExtras();

    /*//from w  w w  .j  ava2 s  . c o  m
     * TO DO! CHANGE WHAT THE MESSAGES DO!!
     */

    for (String key : extras.keySet()) {
        Log.i(getClass().getSimpleName(), String.format("onMessage: %s=%s", key, extras.getString(key)));

        if (key.equals(KillerConstants.EXTRA_KEY_AUDIO)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh pushAudio");
            Intent i = new Intent();
            Log.i("REMOVE BEFORE COMMIT", extras.getString(key));

            Bundle bundle = new Bundle();
            //Add your data to bundle
            bundle.putString(KillerConstants.EXTRA_KEY_AUDIO, extras.getString(key));
            //Add the bundle to the intent
            i.putExtras(bundle);
            i.setClassName("com.arthackday.killerapp", "com.arthackday.killerapp.PushAudio");
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(i);
        }

        if (key.equals(KillerConstants.EXTRA_KEY_PUSHCALL)) {
            Log.i("REMOVE BEFORE COMMIT", "blahhhhhhh callnumber");
            String number = extras.getString(KillerConstants.EXTRA_KEY_PUSHCALL);
            String uri = "tel:" + number.trim();
            Intent intent = new Intent(Intent.ACTION_CALL);
            intent.setData(Uri.parse(uri));
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
}

From source file:com.ushahidi.android.app.BackgroundService.java

private void showNotification(String tickerText) {

    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newUshahidiReportNotification = new Notification(R.drawable.notification_icon, tickerText,
            System.currentTimeMillis());
    newUshahidiReportNotification.contentIntent = contentIntent;
    newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL;
    newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);

    if (Preferences.ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newUshahidiReportNotification.sound = ringURI;
    }//  ww  w  . jav  a  2s. c  o m

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

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

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

    mNotificationManager.notify(Preferences.NOTIFICATION_ID, newUshahidiReportNotification);
}

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void sendGoHomeIntent(Context ctx) {
    Intent i = new Intent(ctx, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    i.putExtra("gohome-frostwire", true);
    ctx.startActivity(i);/*from  w w  w . j ava  2 s .  c o  m*/
}

From source file:de.appplant.cordova.emailcomposer.EmailComposerImpl.java

/**
 * The intent with the containing email properties.
 *
 * @param params//from  w  w w .  jav a 2  s .c o m
 * The email properties like subject or body
 * @param ctx
 * The context of the application.
 * @return
 * The resulting intent.
 * @throws JSONException
 */
public Intent getDraftWithProperties(JSONObject params, Context ctx) throws JSONException {

    Intent mail = new Intent(Intent.ACTION_SEND_MULTIPLE);
    String app = params.optString("app", null);

    if (params.has("subject"))
        setSubject(params.getString("subject"), mail);
    if (params.has("body"))
        setBody(params.getString("body"), params.optBoolean("isHtml"), mail);
    if (params.has("to"))
        setRecipients(params.getJSONArray("to"), mail);
    if (params.has("cc"))
        setCcRecipients(params.getJSONArray("cc"), mail);
    if (params.has("bcc"))
        setBccRecipients(params.getJSONArray("bcc"), mail);
    if (params.has("attachments"))
        setAttachments(params.getJSONArray("attachments"), mail, ctx);

    if (!app.equals(MAILTO_SCHEME) && isAppInstalled(app, ctx)) {
        mail.setPackage(app);
    }

    mail.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    return mail;
}

From source file:com.ushahidi.android.app.UshahidiService.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
    newUshahidiReportNotification = new Notification(R.drawable.favicon, tickerText,
            System.currentTimeMillis());
    newUshahidiReportNotification.contentIntent = contentIntent;
    newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL;
    newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);

    if (UshahidiPref.ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newUshahidiReportNotification.sound = ringURI;
    }//from w w w  . j ava  2  s  .c o  m

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

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

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

    mNotificationManager.notify(UshahidiPref.NOTIFICATION_ID, newUshahidiReportNotification);
}

From source file:com.appnexus.opensdk.mediatednativead.InMobiNativeAdResponse.java

boolean setResources(final InMobiNative imNative) {
    this.imNative = imNative;
    try {//from  w w w . j  av  a2  s .  c om
        nativeElements.put(InMobiSettings.NATIVE_ELEMENT_OBJECT, imNative);
        JSONObject response = new JSONObject((String) imNative.getAdContent());
        title = JsonUtil.getJSONString(response, InMobiSettings.KEY_TITLE);
        callToAction = JsonUtil.getJSONString(response, InMobiSettings.KEY_CALL_TO_ACTION);
        description = JsonUtil.getJSONString(response, InMobiSettings.KEY_DESCRIPTION);
        JSONObject iconObject = JsonUtil.getJSONObject(response, InMobiSettings.KEY_ICON);
        iconUrl = JsonUtil.getJSONString(iconObject, InMobiSettings.KEY_URL);
        JSONObject imageObject = JsonUtil.getJSONObject(response, InMobiSettings.KEY_IMAGE);
        imageUrl = JsonUtil.getJSONString(imageObject, InMobiSettings.KEY_URL);
        if (JsonUtil.getJSONDouble(response, InMobiSettings.KEY_RATING) >= 0) {
            rating = new Rating(JsonUtil.getJSONDouble(response, InMobiSettings.KEY_RATING), 5);
        }
        landingUrl = JsonUtil.getJSONString(response, InMobiSettings.KEY_LANDING_URL);
        clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imNative.reportAdClick(null); // no additional params passed in for click tracking
                onAdClicked();
                if (v != null && landingUrl != null && !landingUrl.isEmpty()) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(landingUrl));
                    browserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    onAdWillLeaveApplication();
                    v.getContext().startActivity(browserIntent);
                }
            }
        };
        return true;
    } catch (Exception e) {
        // Catches JSONException for parsing,
        // ClassCastException for String casting,
        // NPE for null imNative
    }
    return false;
}

From source file:codepath.watsiapp.activities.BaseFragmentActivity.java

private void logout() {
    prefs.clearAll();/*from ww w  .j  av a  2s.c o m*/
    ParseUser.logOut();

    // FLAG_ACTIVITY_CLEAR_TASK only works on API 11, so if the user
    // logs out on older devices, we'll just exit.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Intent intent = new Intent(BaseFragmentActivity.this, WatsiMainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        finish();
    }
}