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:com.example.tacademy.miniproject.gcm.MyGcmListenerService.java

private void sendNotification(ChatMessage m) {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.putExtra(ChatActivity.EXTRA_USER, m.getSender());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new android.support.v7.app.NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setTicker("Chat Message")
            .setContentTitle(m.getSender().getUserName()).setContentText(m.getMessage()).setAutoCancel(true)
            .setDefaults(android.support.v7.app.NotificationCompat.DEFAULT_ALL).setContentIntent(pendingIntent);

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

From source file:id.satusatudua.sigap.ui.EnterCodeActivity.java

@Override
public void onSuccessVerification(User user) {
    new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher).setTitle(R.string.app_name).setCancelable(false)
            .setMessage(//from  w w w .j  av  a 2s.  c om
                    "Kode berhasil diverifikasi, Selanjutnya silahkan atur kata sandi anda pada halaman berikutnya.")
            .setPositiveButton("OK", (dialog, which) -> {
                Intent intent = new Intent(this, UpdatePasswordActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }).show().getButton(DialogInterface.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
}

From source file:org.alfresco.mobile.android.application.extension.samsung.pen.SNoteSDKDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(PARAM_SDK_ERROR)) {
        error = getArguments().getInt(PARAM_SDK_ERROR);
    }/*w w  w . j  a  v  a2s.  c o m*/
    // Messages informations
    int titleId = R.string.error_sdk_dialog;
    int iconId = R.drawable.ic_application_icon;
    int messageId = R.string.error_sdk_unsupported;
    switch (error) {
    case SsdkUnsupportedException.DEVICE_NOT_SUPPORTED:
        messageId = R.string.error_sdk_unsupported;
        break;
    case SsdkUnsupportedException.LIBRARY_NOT_INSTALLED:
        messageId = R.string.error_sdk_library_not_installed;
        break;
    case SsdkUnsupportedException.LIBRARY_UPDATE_IS_REQUIRED:
        messageId = R.string.error_sdk_library_update_required;
        break;

    case SsdkUnsupportedException.LIBRARY_UPDATE_IS_RECOMMENDED:
        messageId = R.string.error_sdk_library_update_recommended;
        break;

    default:
        break;
    }
    setCancelable(false);

    int positiveId = android.R.string.ok;
    int negativeId = android.R.string.cancel;

    String message = getString(messageId);

    Builder builder = new AlertDialog.Builder(getActivity()).setIcon(iconId).setTitle(titleId)
            .setMessage(Html.fromHtml(message)).setCancelable(false)
            .setPositiveButton(positiveId, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    Uri uri = Uri.parse("market://details?id=" + Spen.SPEN_NATIVE_PACKAGE_NAME);
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    getActivity().startActivity(intent);

                    dialog.dismiss();
                    getActivity().finish();
                }
            }).setNegativeButton(negativeId, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    getActivity().finish();
                }
            });
    return builder.create();
}

From source file:id.satusatudua.sigap.ui.VerificationActivity.java

@Override
public void onSuccessVerification(User user) {
    new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher).setTitle(R.string.app_name).setCancelable(false)
            .setMessage(/*from w  ww  .  j a v a 2s . c om*/
                    "Kode berhasil diverifikasi, Selanjutnya silahkan atur kata sandi anda pada halaman berikutnya.")
            .setPositiveButton("OK", (dialog, which) -> {
                Intent intent = new Intent(this, SetPasswordActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }).show().getButton(DialogInterface.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
}

From source file:ch.bfh.instacircle.service.NetworkService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // Initializing the dbHelper in order to get access to the database
    dbHelper = NetworkDbHelper.getInstance(this);

    // Create a pending intent which will be invoked after tapping on the
    // Android notification
    Intent notificationIntent = new Intent(this, NetworkActiveActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            notificationIntent.getFlags());

    // Setting up the notification which is being displayed
    Notification.Builder notificationBuilder = new Notification.Builder(this);
    notificationBuilder.setContentTitle(getResources().getString(R.string.app_name));
    notificationBuilder.setContentText("An InstaCircle Chat session is running. Tap to bring in front.");
    notificationBuilder.setSmallIcon(R.drawable.glyphicons_244_conversation);
    notificationBuilder.setContentIntent(pendingNotificationIntent);
    notificationBuilder.setOngoing(true);
    Notification notification = notificationBuilder.getNotification();

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

    notificationManager.notify(TAG, 1, notification);

    udpBroadcastReceiverThreads = new UDPBroadcastReceiverThread[100];
    tcpUnicastReceiverThreads = new TCPUnicastReceiverThread[100];

    // starting 100 threads allocating 100 Ports
    for (int i = 0; i < 50; i++) {
        udpBroadcastReceiverThreads[i] = new UDPBroadcastReceiverThread(this, i + 12300);
        tcpUnicastReceiverThreads[i] = new TCPUnicastReceiverThread(this, i + 12300);

        udpBroadcastReceiverThreads[i].start();
        tcpUnicastReceiverThreads[i].start();
    }//from  w  w  w  .jav  a 2 s  . co m

    // Register a broadcastreceiver in order to get notification from the UI
    // when a message should be sent
    LocalBroadcastManager.getInstance(this).registerReceiver(messageSendReceiver,
            new IntentFilter("messageSend"));

    // Opening a conversation
    dbHelper.openConversation(getSharedPreferences(PREFS_NAME, 0).getString("password", "N/A"));

    // joining the conversation using the identification in the preferences
    // file
    joinNetwork(getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A"));

    // start the NetworkActiveActivity
    intent = new Intent(this, NetworkActiveActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
    startActivity(intent);
    return super.onStartCommand(intent, flags, startId);
}

From source file:org.catnut.ui.HelloActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApp = CatnutApp.getTingtingApp();/*  w w w.j av a  2s. com*/
    mPreferences = mApp.getPreferences();
    fetch500px();
    // ?????????
    AccessToken accessToken = mApp.getAccessToken();
    if (accessToken == null || System.currentTimeMillis() > accessToken.expires_in) {
        mApp.invalidateAccessToken();
        Toast.makeText(this, getString(R.string.not_yet_auth), Toast.LENGTH_SHORT).show();
        startActivity(new Intent(this, NoHistoryActivity.class));
    } else {
        // ?
        CatnutUtils.checkout(false, this, mPreferences);
        // ?
        if (getIntent().hasExtra(TAG)) {
            init();
        } else if (ACTION_FROM_GRID.equals(getIntent().getAction())) {
            mTargetFromGrid = new Image();
            mTargetFromGrid.url = getIntent().getStringExtra(Photo.image_url);
            mTargetFromGrid.name = getIntent().getStringExtra(Photo.name);
            init();
        } else {
            if (CatnutApp.getBoolean(R.string.pref_enter_home_directly, R.bool.pref_enter_home_directly)) {
                startActivity(new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK
                        | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION));
            } else {
                init();
            }
        }
    }
}

From source file:at.ac.tuwien.caa.docscan.ui.StartActivity.java

private void startCamera() {

    Intent intent = new Intent(this, CameraActivity.class);
    intent.setFlags(/*from  w  w w.j  ava2  s .c  o  m*/
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);

    finish();

}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.ExternalPebbleJSActivity.java

@Override
protected void onNewIntent(Intent incoming) {
    incoming.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    super.onNewIntent(incoming);
    confUri = incoming.getData();//from  w  w  w .  j  a v a2  s .  c om
}

From source file:id.satusatudua.sigap.ui.RegisterActivity.java

@Override
public void onSuccessRegister(User user) {
    new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher).setTitle(R.string.app_name).setCancelable(false)
            .setMessage(// w w  w . jav  a2  s.c o m
                    "Kami telah mengirimkan sebuah kode ke email yang anda daftarkan tadi, masukan kode tersebut ke form selanjutnya untuk memverikasi alamat email anda.")
            .setPositiveButton("OK", (dialog, which) -> {
                sendBroadcast(new Intent("id.satusatudua.sigap.ACTION_START"));
                Intent intent = new Intent(this, VerificationActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }).show().getButton(DialogInterface.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
}

From source file:com.jackie.notifyingUser.PingService.java

private void issueNotification(String msg) {
    // Sets up the Snooze and Dismiss action buttons that will appear in the
    // expanded view of the notification.
    Intent dismissIntent = new Intent(this, PingService.class);
    dismissIntent.setAction(CommonConstants.ACTION_DISMISS);
    PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0);

    Intent snoozeIntent = new Intent(this, PingService.class);
    snoozeIntent.setAction(CommonConstants.ACTION_SNOOZE);
    PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_stat_notification);
    builder.setContentTitle(getString(R.string.notification));
    builder.setContentText(getString(R.string.ping));
    builder.setDefaults(Notification.DEFAULT_ALL); // requires VIBRATE permission;

    /*/*from   w  ww  .  j a  v  a 2 s .c  om*/
     * Sets the big view "big text" style and supplies the text (the user's reminder message)
     * that will be displayed in the detail area of the expanded notification.
     * these calls are ignored by the support library for pre-5.1 devices.
     */
    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(msg));
    builder.addAction(R.drawable.ic_stat_dismiss, getString(R.string.dismiss), piDismiss);
    builder.addAction(R.drawable.ic_stat_snooze, getString(R.string.snooze), piSnooze);

    /*
     * Clicking the notification itself displays ResultActivity, which provides UI for snoozing
     * or dismissing the notification.
     * This is available through either the normal view or big view.
     */
    Intent resultIntent = new Intent(this, ResultActivity.class);
    resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    // Because clicking the notification launches a new ("special") activity,
    // there's no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // this sets the pending intent that should be fired when the user clicks the
    // notification. Clicking the notification launches a new activity.
    builder.setContentIntent(resultPendingIntent);
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mNotificationManager.notify(CommonConstants.NOTIFICATION_ID, builder.build());
}