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.oakesville.mythling.MediaPagerActivity.java

protected void goListView(String mode) {
    if (mediaList.getMediaType() == MediaType.recordings
            && getAppSettings().getMediaSettings().getSortType() == SortType.byTitle)
        getAppSettings().clearCache(); // refresh since we're switching from flattened hierarchy

    if (getPath() == null || getPath().isEmpty()) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(MODE_SWITCH, mode);
        intent.putExtra(SEL_ITEM_INDEX, getSelItemIndex());
        startActivity(intent);//w  w w.j  a  v  a2s .com
    } else {
        Uri uri = new Uri.Builder().path(getPath()).build();
        Intent intent = new Intent(Intent.ACTION_VIEW, uri, getApplicationContext(), MediaListActivity.class);
        intent.putExtra(MODE_SWITCH, mode);
        intent.putExtra(SEL_ITEM_INDEX, getSelItemIndex());
        startActivity(intent);
    }
}

From source file:com.ohnemax.android.glass.doseview.CSDataSort.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {

        // Get an instance of a live card
        mLiveCard = new LiveCard(this, LIVE_CARD_TAG);

        // Inflate a layout into a remote view
        mLiveCardView = new RemoteViews(getPackageName(), R.layout.service_doserate);

        // Set up the live card's action with a pending intent
        // to show a menu when tapped
        Intent menuIntent = new Intent(this, MenuActivity.class);
        menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));

        // Publish the live card
        mLiveCard.publish(PublishMode.REVEAL);

        // Queue the update text runnable
        mHandler.post(mUpdateLiveCardRunnable);
    }/*from   w w w . j a  v  a2  s  .c o m*/
    return START_STICKY;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppReferenceObj.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 (DBG)
        Log.d(TAG, "activating from appReferenceObj: " + content);

    if (!content.has(DbObject.CHILD_FEED_NAME)) {
        Log.wtf(TAG, "Bad app reference found.");
        Toast.makeText(context, "Could not launch application.", Toast.LENGTH_SHORT).show();
        return;
    }

    Log.w(TAG, "Using old-school app launch");
    SignedObj appContent = getAppStateForChildFeed(context, obj);
    if (appContent == null) {
        Intent launch = AppStateObj.getLaunchIntent(context, obj);
        if (!(context instanceof Activity)) {
            launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }

        context.startActivity(launch);
    } else {
        if (DBG)
            Log.d(TAG, "pulled app state " + appContent);
        try {
            appContent.getJson().put(PACKAGE_NAME, content.get(PACKAGE_NAME));
            appContent.getJson().put(OBJ_INTENT_ACTION, content.get(OBJ_INTENT_ACTION));
            appContent.getJson().put(DbObject.CHILD_FEED_NAME, content.get(DbObject.CHILD_FEED_NAME));
        } catch (JSONException e) {
        }
        //mAppStateObj.activate(context, appContent);
        Log.wtf(TAG, "dead code exception");
    }
}

From source file:com.dv.Utils.Tools.java

/**
 * install app//  w  w  w . j a v  a  2 s .  com
 *
 * @param context
 * @param filePath
 * @return whether apk exist
 */
public static boolean install(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    File file = new File(filePath);

    if ((file != null) && (file.length() > 0) && file.exists() && file.isFile()) {
        i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);

        return true;
    }

    return false;
}

From source file:com.aware.ESM.java

@Override
public void onCreate() {
    super.onCreate();

    TAG = Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0
            ? Aware.getSetting(getApplicationContext(), Aware_Preferences.DEBUG_TAG)
            : TAG;/*from  w w  w .  j a v  a  2 s . com*/

    DATABASE_TABLES = ESM_Provider.DATABASE_TABLES;
    TABLES_FIELDS = ESM_Provider.TABLES_FIELDS;
    CONTEXT_URIS = new Uri[] { ESM_Data.CONTENT_URI };

    IntentFilter filter = new IntentFilter();
    filter.addAction(ESM.ACTION_AWARE_QUEUE_ESM);
    registerReceiver(esmMonitor, filter);

    intent_ESM = new Intent(this, ESM_Queue.class);
    intent_ESM.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    pending_ESM = PendingIntent.getActivity(this, 0, intent_ESM, PendingIntent.FLAG_UPDATE_CURRENT);

    if (Aware.DEBUG)
        Log.d(TAG, "ESM service created!");
}

From source file:com.orange.oidc.secproxy_service.Service.java

void resetCookies() {
    // init intent
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClass(Service.this, WebViewActivity.class);

    intent.putExtra("resetcookies", "true");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    // launch webview
    startActivity(intent);// w w w  .  j ava  2 s  .  c  o m
}

From source file:com.snappy.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from   w ww. ja  v a  2s .c  o  m*/
private void generateNotification(Context context, String message, String fromName, Bundle pushExtras,
        String body) {

    db = new LocalDB(context);
    List<LocalMessage> myMessages = db.getAllMessages();

    // Open a new activity called GCMMessageView
    Intent intento = new Intent(this, SplashScreenActivity.class);
    intento.replaceExtras(pushExtras);
    // Pass data to the new activity
    intento.putExtra(Const.PUSH_INTENT, true);
    intento.setAction(Long.toString(System.currentTimeMillis()));
    intento.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

    // Starts the activity on notification click
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the notification with a notification builder
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis())
            .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message))
            .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS)
            .setContentText(body).setContentIntent(pIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message));

    for (int i = 0; i < myMessages.size(); i++) {

        inboxStyle.addLine(myMessages.get(i).getMessage());
    }

    notification.setStyle(inboxStyle);

    // Remove the notification on click
    //notification.flags |= Notification.FLAG_AUTO_CANCEL;
    //notification.defaults |= Notification.DEFAULT_VIBRATE;
    //notification.defaults |= Notification.DEFAULT_SOUND;
    //notification.defaults |= Notification.DEFAULT_LIGHTS;

    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    manager.notify(R.string.app_name, notification.build());
    {
        // Wake Android Device when notification received
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        final PowerManager.WakeLock mWakelock = pm
                .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH");
        mWakelock.acquire();
        // Timer before putting Android Device to sleep mode.
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            public void run() {
                mWakelock.release();
            }
        };
        timer.schedule(task, 5000);
    }
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

/**
 * Handle export in the provided background thread
 *///  w w w.j a  v a  2  s .  co m
private void handleOsmExport(boolean includeAddress, boolean includeFixme) {
    //TODO handle empty survey
    //TODO handle bounds around +/-180

    if (!isExternalStorageWritable()) {
        notifyUserOfError();
        return;
    }

    int id = 0;
    double minLat = 200;
    double minLng = 200;
    double maxLat = -200;
    double maxLng = -200;
    StringBuilder builder = new StringBuilder();

    if (includeAddress) {
        Uri uri = AddressTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                AddressTableMetaData.LATITUDE, AddressTableMetaData.LONGITUDE, AddressTableMetaData.NUMBER,
                AddressTableMetaData.STREET }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(AddressTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(AddressTableMetaData.LONGITUDE);
            int iNumber = cursor.getColumnIndex(AddressTableMetaData.NUMBER);
            int iStreet = cursor.getColumnIndex(AddressTableMetaData.STREET);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String number = cursor.getString(iNumber);
                String street = cursor.getString(iStreet);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "addr:housenumber", number);
                addOsmTag(builder, "addr:street", street);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    if (includeFixme) {
        Uri uri = FixmeTableMetaData.CONTENT_URI;
        Cursor cursor = getContentResolver().query(uri, new String[] { //projection
                FixmeTableMetaData.LATITUDE, FixmeTableMetaData.LONGITUDE, FixmeTableMetaData.COMMENT }, null, //selection string
                null, //selection args array of strings
                null); //sort order

        if (cursor == null) {
            notifyUserOfError();
            return;
        }

        try {
            int iLat = cursor.getColumnIndex(FixmeTableMetaData.LATITUDE);
            int iLong = cursor.getColumnIndex(FixmeTableMetaData.LONGITUDE);
            int iComment = cursor.getColumnIndex(FixmeTableMetaData.COMMENT);

            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                //Gather values
                double lat = cursor.getDouble(iLat);
                double lng = cursor.getDouble(iLong);
                String comment = cursor.getString(iComment);

                minLat = Math.min(minLat, lat);
                maxLat = Math.max(maxLat, lat);
                minLng = Math.min(minLng, lng);
                maxLng = Math.max(maxLng, lng);
                builder.append("<node id=\"-").append(++id).append("\" lat=\"").append(lat).append("\" lon=\"")
                        .append(lng).append("\" version=\"1\" action=\"modify\">\n");
                addOsmTag(builder, "fixme", comment);
                builder.append("</node>\n");
            }
        } finally {
            cursor.close();
        }
    }

    try {
        File destinationFile = getDestinationFile();
        destinationFile.getParentFile().mkdirs();
        PrintWriter writer = new PrintWriter(destinationFile, "UTF-8");

        writer.println("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>");
        writer.println("<osm version=\"0.6\" generator=\"OsmOnTheGo\">");
        writer.print("<bounds minlat=\"");
        writer.print(minLat - MARGIN);
        writer.print("\" minlon=\"");
        writer.print(minLng - MARGIN);
        writer.print("\" maxlat=\"");
        writer.print(maxLat + MARGIN);
        writer.print("\" maxlon=\"");
        writer.print(maxLng + MARGIN);
        writer.println("\" />");

        writer.println(builder);

        writer.print("</osm>");
        writer.close();

        if (writer.checkError()) {
            notifyUserOfError();
        } else {
            //FIXME i18n the subject and content
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            emailIntent.setType(HTTP.OCTET_STREAM_TYPE);
            //emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"johndoe@exemple.com"});
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "OSM On The Go");
            emailIntent.putExtra(Intent.EXTRA_TEXT, "Your last survey.");
            emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(destinationFile));
            startActivity(emailIntent);
        }
    } catch (IOException e) {
        Log.e(TAG, "Could not write to file", e);
        notifyUserOfError();
    }

}

From source file:au.id.micolous.frogjump.Util.java

public static void navigateTo(int latE6, int lngE6, MainActivity.NavigationMode navigationMode,
        Context context) {/*from ww w.j  ava  2s.  c  o m*/
    // Lets make that a decimal again
    String geoloc = String.format("%1$d.%2$06d,%3$d.%4$06d", latE6 / 1000000, Math.abs(latE6 % 1000000),
            lngE6 / 1000000, Math.abs(lngE6 % 1000000));

    Intent intent = null;
    if (navigationMode == MainActivity.NavigationMode.CROW_FLIES
            || navigationMode == MainActivity.NavigationMode.SHOW_MAP) {
        geoloc = "geo:" + geoloc + "?q=" + geoloc;
        Uri geouri = Uri.parse(geoloc);
        intent = new Intent(Intent.ACTION_VIEW, geouri);
        if (navigationMode == MainActivity.NavigationMode.CROW_FLIES) {
            intent.setPackage(GPS_STATUS);
        }
    } else if (navigationMode != MainActivity.NavigationMode.OFF) {
        geoloc = "google.navigation:q=" + geoloc;
        switch (navigationMode) {
        // https://developers.google.com/maps/documentation/directions/intro#Restrictions
        // The intent service supports this parameter too, but it is not documented.
        case DRIVING_AVOID_TOLLS:
            geoloc += "&avoid=tolls";
        case DRIVING:
            geoloc += "&mode=d";
            break;
        case CYCLING:
            geoloc += "&mode=b";
            break;
        case WALKING:
            geoloc += "&mode=w";
            break;
        }

        // Launch Google Maps
        Uri geouri = Uri.parse(geoloc);
        intent = new Intent(Intent.ACTION_VIEW, geouri);
        intent.setPackage(GOOGLE_MAPS);
    }

    if (intent != null) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
}