Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

Usage

From source file:org.jboss.aerogear.android.cookbook.aerodoc.handler.NotifyingMessageHandler.java

private void sendNotification(String msg) {
    NotificationManager mNotificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(ctx, AeroDocActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
            .putExtra("alert", msg);

    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx).setAutoCancel(true)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("AeroGear Push Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:id.zelory.tanipedia.activity.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (PrefUtils.ambilString(this, "nama") != null) {
        Intent intent = new Intent(LoginActivity.this, CuacaActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);//from w  w w . ja v a  2s . c  o m
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
    findViewById(R.id.tanipedia).startAnimation(animation);
    findViewById(R.id.card).startAnimation(animation);
    Button login = (Button) findViewById(R.id.login);
    login.startAnimation(animation);
    login.setOnClickListener(this);
    TextView daftar = (TextView) findViewById(R.id.register);
    daftar.startAnimation(animation);
    daftar.setOnClickListener(this);
    editEmail = (EditText) findViewById(R.id.email);
    editPass = (EditText) findViewById(R.id.password);
}

From source file:com.eeec.GestionEspresso.gcm.KGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//  w w  w .j  a v a2  s.c  o  m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification).setColor(getResources().getColor(R.color.colorPrimary))
            .setContentText(message).setContentTitle("Gestin Espresso").setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}

From source file:com.psu.capstonew17.pdxaslapp.BaseActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] perms, @NonNull int[] grantResults) {
    switch (requestCode) {
    //check for external storage perms
    case REQ_EXT_STORAGE_PERMS:
        if (grantResults.length > 0 && !(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
            //if the user refuses external storage perms then trap them! muahahahaha!
            //(okay, not really, but don't let them continue to try to use the app)
            Intent intent = new Intent(this, NoExtrnlStrgPrmsActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);//from w ww  . ja va 2 s  .  c om
        }
        break;
    }
}

From source file:com.chefsglass.StopwatchService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (mLiveCard == null) {
        mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
        new GetRecipeTask(new GetRecipeRequest(1l)).execute();

        // Keep track of the callback to remove it before unpublishing.
        mCallback = new RecipeDrawer(this);
        mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);

        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));
        mLiveCard.attach(this);
        mLiveCard.publish(PublishMode.REVEAL);
    } else {//from w w w .j a va 2 s  . c om
        mLiveCard.navigate();
    }

    return START_STICKY;
}

From source file:com.nextzy.oneassetmanagement.common.BaseActivity.java

protected void openActivityAndClearHistory(Class<?> cls, Bundle bundle) {
    Intent intent = new Intent(this, cls);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    if (bundle != null)
        intent.putExtras(bundle);/*from  ww w  .j  a  va2  s  .c  om*/
    startActivity(intent);
}

From source file:com.geekandroid.sdk.base.BaseFragment.java

public void startActivityClearTask(Class<?> cls) {
    Intent intent = new Intent(getActivity(), cls);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);/*ww  w . j a v a2s.c  o  m*/
}

From source file:com.demo.push.GcmListener.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  w ww .  j  av a  2s  . co m*/
 */
private void sendNotification(String message) {

    Intent intent = new Intent(this, LandingActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 0);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.tortel.deploytrack.dialog.DatabaseUpgradeDialog.java

/**
 * Restart the main activity/*from   ww  w .ja v  a 2  s  . c o  m*/
 */
private void restartMainActivity() {
    try {
        dismissAllowingStateLoss();
    } catch (Exception e) {
        // Ignore, being careful here.
    }

    Intent intent = new Intent(getActivity(), MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    getActivity().startActivity(intent);
}

From source file:com.heightechllc.breakify.AlarmNotifications.java

/**
 * Shows an ongoing notification for an upcoming alarm
 * @param context The context to create the notification from
 * @param ringTime The time that the alarm will ring, based on `SystemClock.elapsedRealtime()`
 * @param workState The work state of the timer
 *///from  w w w .  j a v  a2s .c  o m
public static void showUpcomingNotification(Context context, long ringTime, int workState) {
    // Create the notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(R.drawable.ic_notification).setOngoing(true)
            .setPriority(NotificationCompat.PRIORITY_LOW);

    // Get the appropriate title based on the current work state
    int titleId = workState == MainActivity.WORK_STATE_WORKING ? R.string.notif_upcoming_title_working
            : R.string.notif_upcoming_title_breaking;

    builder.setContentTitle(context.getString(titleId));

    // Get formatted time for when the alarm will ring. We need to convert `ringTime`, which
    //  is based on `SystemClock.elapsedRealtime()`, to a regular Unix / epoch time
    long timeFromNow = ringTime - SystemClock.elapsedRealtime();
    long ringUnixTime = System.currentTimeMillis() + timeFromNow;
    // Construct the text, e.g., "Until 11:30"
    String contentText = context.getString(R.string.notif_upcoming_content_text) + " ";
    contentText += DateFormat.getTimeFormat(context).format(new Date(ringUnixTime));

    builder.setContentText(contentText);

    // Set up the action for the when the notification is clicked - to open MainActivity
    Intent mainIntent = new Intent(context, MainActivity.class);
    mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pi = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(pi);

    // Show the notification
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationID, builder.build());
}