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.linroid.pushapp.ui.bind.BindActivity.java

private void redirectToHome() {
    Intent intent = new Intent(this, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);//from   w  ww.j  a  va  2s . com
    finish();
}

From source file:in.codehex.arrow.LoginActivity.java

/**
 * Authenticates the user. Sends HTTP POST request to the server.
 *//*from   ww w. j  a  v a 2 s  . com*/
private void processLogin() {
    showProgressDialog();

    StringRequest stringRequest = new StringRequest(Request.Method.POST, Config.URL_API,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    hideProgressDialog();
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        int error = jsonObject.getInt("error");
                        String message = jsonObject.getString("message");

                        Toast.makeText(LoginActivity.this, message, Toast.LENGTH_SHORT).show();

                        if (error == 0) {
                            SharedPreferences.Editor editor = userPreferences.edit();
                            editor.putString(Config.KEY_PREF_NAME, name);
                            editor.putString(Config.KEY_PREF_PHONE, phone);
                            editor.putString(Config.KEY_PREF_IMEI, imei);
                            editor.apply();

                            intent = new Intent(LoginActivity.this, MainActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hideProgressDialog();
                    Toast.makeText(LoginActivity.this, "Network error! Please check your internet connection!",
                            Toast.LENGTH_SHORT).show();
                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("tag", "user");
            params.put("name", name);
            params.put("imei", imei);
            return params;
        }
    };
    AppController.getInstance().addToRequestQueue(stringRequest, "user");
}

From source file:org.awesomeapp.messenger.ui.GalleryListItem.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onClickMediaIcon(String mimeType, Uri mediaUri) {

    if (SecureMediaStore.isVfsUri(mediaUri)) {
        if (mimeType.startsWith("image")) {
            Intent intent = new Intent(context, ImageViewActivity.class);
            intent.putExtra(ImageViewActivity.URI, mediaUri.toString());
            intent.putExtra(ImageViewActivity.MIMETYPE, mimeType);

            context.startActivity(intent);
            return;
        }/*w  w  w.j a  va  2 s. c  o  m*/
        return;
    } else {

        String body = convertMediaUriToPath(mediaUri);

        if (body == null)
            body = new File(mediaUri.getPath()).getAbsolutePath();

        if (mimeType.startsWith("audio")
                || (body.endsWith("3gp") || body.endsWith("3gpp") || body.endsWith("amr"))) {

            if (mMediaPlayer != null)
                mMediaPlayer.release();

            try {
                mMediaPlayer = new MediaPlayer();
                mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mMediaPlayer.setDataSource(body);
                mMediaPlayer.prepare();
                mMediaPlayer.start();

                return;
            } catch (IOException e) {
                Log.e(ImApp.LOG_TAG, "error playing audio: " + body, e);
            }

        }

        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (Build.VERSION.SDK_INT >= 11)
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        //set a general mime type not specific
        intent.setDataAndType(Uri.parse(body), mimeType);

        Context context = getContext().getApplicationContext();

        if (isIntentAvailable(context, intent)) {
            context.startActivity(intent);
        } else {
            Toast.makeText(getContext(), R.string.there_is_no_viewer_available_for_this_file_format,
                    Toast.LENGTH_LONG).show();
        }
    }
}

From source file:rp.soi.dmsd.notextingwhilewalking.DetectedActivitiesIntentService.java

public void createNotification(boolean makeHeadsUpNotification) {

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_priority_high_black_24dp).setPriority(Notification.PRIORITY_DEFAULT)
            .setCategory(Notification.CATEGORY_MESSAGE).setContentTitle("No-Texting-While-Walking")
            .setContentText("It is hazardous to be texting while walking.");

    if (makeHeadsUpNotification) {

        Intent push = new Intent(getApplication(), MainActivity.class);
        push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        //push.setClass(this, MainActivity.class);

        PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, push,
                PendingIntent.FLAG_CANCEL_CURRENT);
        notificationBuilder.setContentText("It is hazardous to be texting while walking.")
                .setFullScreenIntent(fullScreenPendingIntent, true);
    }//  w  ww . jav a 2s  .  c o  m
    Notification notification = notificationBuilder.build();
    //---set the sound and lights---
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    //---gets an instance of the NotificationManager service---
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    //---build the notification and issues it
    // with notification manager---
    notificationManager.notify(WEARABLE_NOTIFICATION_ID, notification);
}

From source file:nu.yona.app.ui.signup.OTPActivity.java

/**
 * Show Passcode Activity and clear back stack.
 *//*from w w  w . ja va 2 s.co  m*/
private void showPasscodeScreen() {
    Intent intent = new Intent(OTPActivity.this, PasscodeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

From source file:fr.free.nrw.commons.Utils.java

/**
 * Opens Custom Tab Activity with in-app browser for the specified URL.
 * Launches intent for web URL/*from  www.j a  v a 2  s.co m*/
 * @param context
 * @param url
 */
public static void handleWebUrl(Context context, Uri url) {
    Timber.d("Launching web url %s", url.toString());
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
    if (browserIntent.resolveActivity(context.getPackageManager()) == null) {
        Toast toast = Toast.makeText(context, context.getString(R.string.no_web_browser), LENGTH_SHORT);
        toast.show();
        return;
    }

    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    builder.setToolbarColor(ContextCompat.getColor(context, R.color.primaryColor));
    builder.setSecondaryToolbarColor(ContextCompat.getColor(context, R.color.primaryDarkColor));
    builder.setExitAnimations(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
    CustomTabsIntent customTabsIntent = builder.build();
    // Clear previous browser tasks, so that back/exit buttons work as intended.
    customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    customTabsIntent.launchUrl(context, url);
}

From source file:org.gnucash.android.ui.widget.WidgetConfigurationActivity.java

/**
 * Updates the widget with id <code>appWidgetId</code> with information from the 
 * account with record ID <code>accountId</code>
  * If the account has been deleted, then a notice is posted in the widget
  * @param appWidgetId ID of the widget to be updated
  * @param accountId Database ID of the account tied to the widget
 *//*from  w w w . ja va2s. c  o  m*/
public static void updateWidget(Context context, int appWidgetId, long accountId) {
    Log.i("WidgetConfiguration", "Updating widget: " + appWidgetId);
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);

    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(context);
    Account account = accountsDbAdapter.getAccount(accountId);

    if (account == null) {
        Log.i("WidgetConfiguration", "Account not found, resetting widget " + appWidgetId);
        //if account has been deleted, let the user know
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
        views.setTextViewText(R.id.account_name, context.getString(R.string.toast_account_deleted));
        views.setTextViewText(R.id.transactions_summary, "");
        //set it to simply open the app
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, AccountsActivity.class), 0);
        views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent);
        views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);
        appWidgetManager.updateAppWidget(appWidgetId, views);
        Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
        editor.remove(UxArgument.SELECTED_ACCOUNT_ID + appWidgetId);
        editor.commit();
        return;
    }

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_4x1);
    views.setTextViewText(R.id.account_name, account.getName());
    Money accountBalance = accountsDbAdapter.getAccountBalance(accountId);

    views.setTextViewText(R.id.transactions_summary, accountBalance.formattedString(Locale.getDefault()));
    int color = account.getBalance().isNegative() ? R.color.debit_red : R.color.credit_green;
    views.setTextColor(R.id.transactions_summary, context.getResources().getColor(color));

    Intent accountViewIntent = new Intent(context, TransactionsActivity.class);
    accountViewIntent.setAction(Intent.ACTION_VIEW);
    accountViewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    accountViewIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId);
    PendingIntent accountPendingIntent = PendingIntent.getActivity(context, appWidgetId, accountViewIntent, 0);
    views.setOnClickPendingIntent(R.id.widget_layout, accountPendingIntent);

    Intent newTransactionIntent = new Intent(context, TransactionsActivity.class);
    newTransactionIntent.setAction(Intent.ACTION_INSERT_OR_EDIT);
    newTransactionIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    newTransactionIntent.putExtra(UxArgument.SELECTED_ACCOUNT_ID, accountId);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, newTransactionIntent, 0);
    views.setOnClickPendingIntent(R.id.btn_new_transaction, pendingIntent);

    appWidgetManager.updateAppWidget(appWidgetId, views);
}

From source file:com.matthewmitchell.wakeifyplus.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.add_alarm:
        startActivityForResult(new Intent(this, AddAlarmActivity.class), 0);
        return true;
    case R.id.logout:
        binder.getService().logout(new LogoutDelegate() {

            @Override/*from ww w.j  a v  a2 s .com*/
            public void onLogout() {
                // Forget user.
                String path = getExternalFilesDir(null).getAbsolutePath();
                path += "/blob.dat";
                Log.i("infodb", "Deleting " + path);
                File blob = new File(path);
                blob.delete();
                // Go to login activity
                Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            }

        });
        /*// Forget user.
          String path = getExternalFilesDir(null).getAbsolutePath();
          path += "/blob.dat";
          Log.i("infodb", "Deleting " + path);
          File blob = new File(path);
          blob.delete();
          // Restart the app. Spotify logout does not function so we need a hack
          Intent mStartActivity = new Intent(this, LoginActivity.class);
          int mPendingIntentId = 123456;
          PendingIntent mPendingIntent = PendingIntent.getActivity(this, mPendingIntentId,    mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
          AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
          mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
          System.exit(0);*/
        return true;
    case R.id.facebook:
        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/Wakeify"));
        startActivity(myIntent);
        return true;
    case R.id.report:
        ReportProblem.reportProblem(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.wso2.emm.agent.services.NotificationService.java

/**
 * This method is used to post a notification in the device.
 *
 * @param operationId id of the calling notification operation.
 * @param messageTitle message title to be displayed
 * @param messageText message text to be displayed
 *///from w  w  w  .  j a v a2s.c om
public void showNotification(int operationId, String messageTitle, String messageText) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent notification = new Intent(context, NotificationReceiver.class);
        notification.putExtra(Constants.OPERATION_ID, operationId);
        PendingIntent dismiss = PendingIntent.getBroadcast(context, operationId, notification,
                PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.notification).setContentTitle(messageTitle).setContentText(messageText)
                .setPriority(android.app.Notification.PRIORITY_MAX)
                .setDefaults(android.app.Notification.DEFAULT_VIBRATE)
                .setDefaults(android.app.Notification.DEFAULT_SOUND)
                .setCategory(android.app.Notification.CATEGORY_CALL).setOngoing(true).setOnlyAlertOnce(true)
                .setTicker(context.getResources().getString(R.string.txt_notification))
                .addAction(R.drawable.abs__ic_clear, "Dismiss", dismiss);

        notifyManager.notify(operationId, mBuilder.build());

    } else {
        Intent intent = new Intent(context, AlertActivity.class);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_message_title), messageTitle);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_message_text), messageText);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_operation_id), operationId);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_type),
                context.getResources().getString(R.string.intent_extra_alert));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        context.startActivity(intent);
    }
}

From source file:org.wso2.iot.agent.services.NotificationService.java

/**
 * This method is used to post a notification in the device.
 *
 * @param operationId id of the calling notification operation.
 * @param messageTitle message title to be displayed
 * @param messageText message text to be displayed
 *///  w w  w .ja va 2 s.c o  m
public void showNotification(int operationId, String messageTitle, String messageText) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Intent notification = new Intent(context, NotificationReceiver.class);
        notification.putExtra(Constants.OPERATION_ID, operationId);
        PendingIntent dismiss = PendingIntent.getBroadcast(context, operationId, notification,
                PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_notifications_white_24dp).setContentTitle(messageTitle)
                .setContentText(messageText).setPriority(android.app.Notification.PRIORITY_MAX)
                .setDefaults(android.app.Notification.DEFAULT_VIBRATE)
                .setDefaults(android.app.Notification.DEFAULT_SOUND)
                .setCategory(android.app.Notification.CATEGORY_CALL).setOngoing(true).setOnlyAlertOnce(true)
                .setTicker(context.getResources().getString(R.string.txt_notification))
                .addAction(R.drawable.dismiss, "Dismiss", dismiss);

        notifyManager.notify(operationId, mBuilder.build());

    } else {
        Intent intent = new Intent(context, AlertActivity.class);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_message_title), messageTitle);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_message_text), messageText);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_operation_id), operationId);
        intent.putExtra(context.getResources().getString(R.string.intent_extra_type),
                context.getResources().getString(R.string.intent_extra_alert));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        context.startActivity(intent);
    }
}