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.bourke.kitchentimer.utils.Utils.java

public static void donate(Context mContext) {
    Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://search?q=Donation%20pub:%22Roberto%20Leinardi%22"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    mContext.startActivity(intent);//from   ww w . j  a  va2s  .  co m
}

From source file:com.sublimis.urgentcallfilter.Magic.java

@SuppressWarnings("deprecation")
private void notification() {
    if (MyPreference.isNotifications()) {
        if (mContext != null) {
            NotificationManager notificationManager = (NotificationManager) mContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);

            if (notificationManager != null) {
                Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
                Intent notificationIntent = new Intent(mContext, ActivityMain.class);

                if (notification != null && notificationIntent != null) {
                    notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent,
                            PendingIntent.FLAG_UPDATE_CURRENT);

                    notification.setLatestEventInfo(mContext,
                            mContext.getResources().getString(R.string.notification_title),
                            mContext.getResources().getString(R.string.notification_text), pendingIntent);

                    notificationManager.notify(0, notification);
                }/*from   w w  w.  j  a  v a2 s  .  co  m*/
            }
        }
    }
}

From source file:com.appteam.nimbus.activity.homeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_logout) {
        personalData.SaveData(false);//from w w w . ja v a 2  s .  c om

        Intent launch_logout = new Intent(homeActivity.this, Login.class);
        launch_logout.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        launch_logout.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        launch_logout.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

        startActivity(launch_logout);
        finish();

        return true;
    } else if (id == R.id.action_leaderboard) {
        startActivity(new Intent(homeActivity.this, Leaderboard.class));
        return true;
    } else if (id == R.id.action_important_contact) {
        CharSequence name[] = { "Ankush Sharma\n(Discipline Secretary)",
                "Rishabh Kumar\n(Discipline Joint Secretary)", "Kumud Jindal\n(Discipline Joint Secretary)", };
        final CharSequence number[] = { "9736688292", "8627090570", "9882263949" };
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setIcon(android.R.drawable.ic_menu_call);
        builder.setTitle("Emergency Contact");
        builder.setItems(name, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:+91" + number[i]));
                startActivity(intent);
            }
        });
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.sigimera.app.android.GCMIntentService.java

@Override
protected final void onMessage(final Context context, final Intent message) {
    final Intent msg = message;
    this.mainThreadHandler.post(new Runnable() {
        public void run() {
            ApplicationController controller = ApplicationController.getInstance();
            controller.init(getApplicationContext(), getSharedPreferences(Constants.PREFS_NAME, 0), null);
            String authToken = controller.getSharedPreferences().getString("auth_token", null);
            final String type = msg.getStringExtra("sig_message_type");
            if (type.equalsIgnoreCase("NEW_CRISIS")) {
                /**//from   w  w w . jav a 2  s .c  om
                 * XXX: Blocks UI: Shift this code into a separate
                 * background thread
                 */
                Crisis crisis = PersistanceController.getInstance().getCrisis(authToken,
                        msg.getStringExtra("crisis_id"));

                StringBuffer message = new StringBuffer();
                if (crisis != null) {
                    message.append(crisis.getID());
                    message.append(" was stored successfully!");
                } else {
                    message.append("Not able to get crisis!");
                }
                Toast.makeText(getApplicationContext(), message.toString(), Toast.LENGTH_LONG).show();
            } else if (type.equalsIgnoreCase("PING")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                Intent notificationIntent = new Intent();
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("Sigimera PING!")
                        .setContentText("Congratulations, push notifcation received!")
                        .setSmallIcon(R.drawable.sigimera_logo).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(Constants.PING_ID, notification);
            } else if (type.equalsIgnoreCase("CRISIS_ALERT")) {
                String ns = Context.NOTIFICATION_SERVICE;
                NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

                /**
                 * XXX: Not working with random ID. That makes always the
                 * latest notification clickable, but not the older ones.
                 */
                int notificationID = new Random().nextInt();
                Intent notificationIntent = new Intent(getApplicationContext(), CrisisAlertActivity.class);
                notificationIntent.putExtra("notification_id", notificationID);
                notificationIntent.putExtra("crisis_id", msg.getStringExtra("crisis_id"));
                notificationIntent.putExtra("crisis_type", msg.getStringExtra("crisis_type"));
                PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0,
                        notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

                Notification notification = new NotificationCompat.Builder(getApplicationContext())
                        .setContentTitle("CRISIS ALERT!")
                        .setContentText("Crisis found: " + msg.getStringExtra("crisis_id"))
                        .setSmallIcon(R.drawable.alert_red).setOngoing(true).setAutoCancel(true)
                        .setDefaults(Notification.DEFAULT_ALL).setContentIntent(contentIntent).build();

                mNotificationManager.notify(notificationID, notification);
            } else if (type.equalsIgnoreCase("SHARED_CRISIS")) {
                Intent intent = new Intent(GCMIntentService.this, CrisisActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra(Constants.CRISIS_ID, msg.getStringExtra("crisis_id"));
                intent.putExtra(Constants.WINDOW_TYPE, Constants.WINDOW_TYPE_SHARED_CRISIS);
                startActivity(intent);
            } else if (type.equalsIgnoreCase("UNREGISTER_DEVICE")) {
                GCMRegistrar.unregister(ApplicationController.getInstance().getApplicationContext());
            } else if (type.equalsIgnoreCase("REFRESH")) {
                LocationUpdaterHttpHelper locUpdater = new LocationUpdaterHttpHelper();
                Location loc = LocationController.getInstance().getLastKnownLocation();
                if (loc != null) {
                    String latitude = loc.getLatitude() + "";
                    String longitude = loc.getLongitude() + "";
                    if (authToken != null) {
                        locUpdater.execute(authToken, latitude, longitude);
                    }
                } else {
                    // TODO: Notify the user that the update location flow
                    // has not worked.
                }
            }
        }
    });
}

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

@Override
public void onBackPressed() {
    if (modeSwitch) {
        modeSwitch = false;/*from ww  w  . java  2s  .  c  o m*/
        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    } else {
        super.onBackPressed();
    }
}

From source file:jahirfiquitiva.iconshowcase.services.NotificationsService.java

@SuppressWarnings("ResourceAsColor")
private void pushNotification(String content, int type, int ID) {

    Preferences mPrefs = new Preferences(this);

    String appName = Utils.getStringFromResources(this, R.string.app_name);

    String title = appName, notifContent = null;

    switch (type) {
    case 1:// w  ww .j  ava  2 s .c om
        title = getResources().getString(R.string.new_walls_notif_title, appName);
        notifContent = getResources().getString(R.string.new_walls_notif_content, content);
        break;
    case 2:
        title = appName + " " + getResources().getString(R.string.news).toLowerCase();
        notifContent = content;
        break;
    }

    // Send Notification
    NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
    notifBuilder.setAutoCancel(true);
    notifBuilder.setContentTitle(title);
    if (notifContent != null) {
        notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notifContent));
        notifBuilder.setContentText(notifContent);
    }
    notifBuilder.setTicker(title);
    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notifBuilder.setSound(ringtoneUri);

    if (mPrefs.getNotifsVibrationEnabled()) {
        notifBuilder.setVibrate(new long[] { 500, 500 });
    } else {
        notifBuilder.setVibrate(null);
    }

    int ledColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.dark_theme_accent)
            : ContextCompat.getColor(this, R.color.light_theme_accent);

    notifBuilder.setColor(ledColor);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notifBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    Class appLauncherActivity = getLauncherClass(getApplicationContext());

    if (appLauncherActivity != null) {
        Intent appIntent = new Intent(this, appLauncherActivity);
        appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        appIntent.putExtra("notifType", type);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(appLauncherActivity);

        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(appIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        notifBuilder.setContentIntent(resultPendingIntent);
    }

    notifBuilder.setOngoing(false);

    notifBuilder.setSmallIcon(R.drawable.ic_notifications);

    Notification notif = notifBuilder.build();

    if (mPrefs.getNotifsLedEnabled()) {
        notif.ledARGB = ledColor;
    }

    notifManager.notify(ID, notif);
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.RviService.java

static void sendNotification(Context ctx, String action, String... extras) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    boolean fire = prefs.getBoolean("pref_fire_notifications", true);

    if (!fire)/*from  w  ww  .  ja v a 2  s.  c o m*/
        return;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.rvi_not)
            .setAutoCancel(true).setContentTitle(ctx.getResources().getString(R.string.app_name))
            .setContentText(action);

    Intent targetIntent = new Intent(ctx, LockActivity.class);
    int j = 0;
    for (String ex : extras) {
        targetIntent.putExtra("_extra" + (++j), ex);
        targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    }
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, targetIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);
    nm.notify(0, builder.build());
}

From source file:com.safecell.HomeScreenActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    // android:background="@drawable/stop_button"

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    Log.v(TAG, "on create");
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setWindowAnimations(R.anim.null_animation);

    contextHomeScreenActivity = HomeScreenActivity.this;

    mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    profilesRepository = new ProfilesRepository(contextHomeScreenActivity);
    isgameplay = this.GamplayOnOff();
    if (!InformatonUtils.isServiceRunning(this)) {
        startService();// ww  w. j ava  2  s.  c om
    }
    // ServiceHandler.getInstance(this).bindService();

    this.initUI();
    Log.v(TAG, "Emergencies.Inbound_Details Size:" + Emergencies.Inbound_Details.size());

    // Request for Emergency numbers
    new EmergencyHandler(contextHomeScreenActivity, profilesRepository.getId()).execute();

    IsTripPaused();
    IsTripSaved();

    Log.d(TAG, "Setings = "
            + getSharedPreferences("SETTINGS", MODE_WORLD_READABLE).getBoolean("isDisabled", false));

    sharedPreferences = getSharedPreferences("TRIP", MODE_WORLD_READABLE);

    this.recentTripLog();

    deleteFile(WayPointStore.WAY_POINT_FILE);
    deleteFile(InterruptionStore.INTERRUPTION_POINT_FILE);

    // setListAdapter(new recentTripAdapater(HomeScreenActivity.this));

    if (isAppTermited())

    {
        deleteLastTempTrip();
        Intent mIntent = new Intent(HomeScreenActivity.this, TrackingScreenActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Log.v("HomeScreenActivity", "AppTerminated");
        startActivity(mIntent);

        finish();
        // clearTrackingScreenPref();
    }

    /*
     * if(!isAppTermited()) { Log.v("SafeCell: Temp data",
     * "Delete Last Data"); deleteLastTempTrip(); }
     */

}

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

private void createShortcut() {
    Intent shortcutIntent = new Intent(this, PreferencesActivity.class);
    shortcutIntent.putExtra(EXTRA_PACKAGE_NAME, packageName);
    shortcutIntent.putExtra(EXTRA_TITLE, title);
    shortcutIntent.putExtra(EXTRA_SHORTCUT, true);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    addIntent.setAction(INSTALL_SHORTCUT);
    sendBroadcast(addIntent);//from w  w  w .j av  a  2 s .c  om
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_SingIn.java

public void backButton() {
    Intent slideactivity = new Intent(Activity_SingIn.this, Activity_Main.class);
    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    Bundle bndlanimation = ActivityOptions
            .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright).toBundle();
    startActivity(slideactivity, bndlanimation);
}