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.sender.team.sender.gcm.MyGcmListenerService.java

private void sendRejectNotification() {
    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(ACTION_REJECT, "reject");
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setTicker("SENDER").setContentTitle("SENDER")
            .setContentText("?  ?").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.globalcollect.gateway.sdk.client.android.exampleapp.fragments.FullWalletConfirmationButtonFragment.java

@Override
public void onPaymentRequestPrepared(PreparedPaymentRequest preparedPaymentRequest) {
    if (mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();/*from w ww  .  j ava2s. com*/
    }

    if (preparedPaymentRequest == null) {
        // Show the user that something went wrong
        showTechnicalErrorDialog();
    } else {

        // Send the PreparedPaymentRequest to the merchant server, this contains a blob of encrypted values + base64encoded metadata
        //
        // Depending on the response from the merchant server, redirect to one of the following pages:
        //
        // - Successful page if the payment is done
        // - Unsuccesful page when the payment result is unsuccessful, you must supply a paymentProductId and an errorcode which will be translated
        // - Webview page to show an instructions page, or to go to a third party payment page
        //
        // Successful and Unsuccessful results have to be redirected to PaymentResultActivity
        // PaymentWebViewActivity is used for showing the Webview

        // For now we fake here that the payment was succesful and go to the successful/unsuccessful page:
        Intent intent = new Intent(getActivity(), PaymentResultActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(Constants.INTENT_PAYMENT_CONTEXT, paymentContext);
        intent.putExtra(Constants.INTENT_SHOPPINGCART, shoppingCart);
        startActivity(intent);
    }
}

From source file:org.wso2.emm.agent.services.operation.OperationManager.java

/**
 * Ring the device./* w w  w  .j  a  v  a 2 s  .  c  o  m*/
 *
 * @param operation - Operation object.
 */
public void ringDevice(org.wso2.emm.agent.beans.Operation operation) {
    operation.setStatus(resources.getString(R.string.operation_value_completed));
    resultBuilder.build(operation);
    Intent intent = new Intent(context, AlertActivity.class);
    intent.putExtra(resources.getString(R.string.intent_extra_type),
            resources.getString(R.string.intent_extra_ring));
    intent.putExtra(resources.getString(R.string.intent_extra_message_text),
            resources.getString(R.string.intent_extra_stop_ringing));
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Ringing is activated on the device");
    }
}

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void goToFrostWireMainActivity(Activity activity) {
    final Intent intent = new Intent(activity, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    activity.startActivity(intent);//from ww  w.  j a v  a2  s.c o  m
    activity.finish();
    activity.overridePendingTransition(0, 0);
}

From source file:org.wso2.mdm.agent.services.Operation.java

/**
 * Display notification.// ww  w  .j ava2 s.  co  m
 * @param code - Operation code.
 */
public void displayNotification(String code) throws AndroidAgentException {
    String notification = null;

    try {
        JSONObject inputData = new JSONObject(code);
        if (inputData.get(resources.getString(R.string.intent_extra_notification)).toString() != null
                && !inputData.get(resources.getString(R.string.intent_extra_notification)).toString()
                        .isEmpty()) {
            notification = inputData.get(resources.getString(R.string.intent_extra_notification)).toString();
        }

        resultBuilder.build(code);

        if (notification != null) {
            Intent intent = new Intent(context, AlertActivity.class);
            intent.putExtra(resources.getString(R.string.intent_extra_message), notification);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }
    } catch (JSONException e) {
        throw new AndroidAgentException("Invalid JSON format.", e);
    }
}

From source file:com.lloydtorres.stately.push.TrixHelper.java

/**
 * Builds a login activity intent with routing, depending on what's on the bundle.
 * @param c App content/*from   w w  w.j av a  2s . c  o m*/
 * @param account Target nation name
 * @param bundle Extra data
 * @return Complete login activity intent
 */
private static Intent getLoginActivityIntent(Context c, String account, Bundle bundle) {
    Intent loginActivityIntent = new Intent(c, LoginActivity.class);
    loginActivityIntent.putExtra(LoginActivity.USERDATA_KEY,
            getUserLoginFromId(c, SparkleHelper.getIdFromName(account)));
    loginActivityIntent.putExtra(LoginActivity.NOAUTOLOGIN_KEY, true);
    loginActivityIntent.putExtra(LoginActivity.ROUTE_BUNDLE_KEY, bundle);
    loginActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    // Apparently this is necessary: http://stackoverflow.com/a/3168653
    loginActivityIntent.setAction(Long.toString(System.currentTimeMillis()));
    return loginActivityIntent;
}

From source file:com.jedi.setupwizard.ui.SetupWizardActivity.java

private void finalizeSetup() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    disableSetupWizards(intent);/*from  w w  w  . ja  v  a  2  s .c  om*/
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

From source file:cz.maresmar.sfm.view.guide.WelcomeActivity.java

@UiThread
private void startMainActivity() {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);/*from  ww w  .j  av  a2  s.  c om*/

    // Plan auto sync in the background
    SyncHandler.planFullSync(this, Integer.parseInt(SettingsContract.SYNC_FREQUENCY_DEFAULT),
            SettingsContract.SYNC_UNMETERED_ONLY_DEFAULT, SettingsContract.SYNC_CHARGING_ONLY_DEFAULT);
}

From source file:com.atahani.telepathy.ui.fragment.AboutDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View customLayout = inflater.inflate(R.layout.fragment_about_dialog, null);
    //config app version information
    mAppPreferenceTools = new AppPreferenceTools(TApplication.applicationContext);
    AppCompatTextView txAndroidAppVerInfo = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_android_ver_info);
    txAndroidAppVerInfo.setText(String.format(getString(R.string.label_telepathy_for_android),
            mAppPreferenceTools.getTheLastAppVersion()));
    txAndroidAppVerInfo.setOnClickListener(new View.OnClickListener() {
        @Override//ww w.j  a  v a  2s .c om
        public void onClick(View v) {
            try {
                //open browser to navigate telepathy website
                Uri telepathyWebSiteUri = Uri.parse("https://github.com/atahani/telepathy-android.git");
                startActivity(new Intent(Intent.ACTION_VIEW, telepathyWebSiteUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config google play store link
    AppCompatTextView txRateUsOnGooglePlayStore = (AppCompatTextView) customLayout
            .findViewById(R.id.tx_rate_us_on_play_store);
    txRateUsOnGooglePlayStore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //navigate to market for rate application
            Uri uri = Uri.parse("market://details?id=" + TApplication.applicationContext.getPackageName());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            // To count with Play market backstack, After pressing back button,
            // to taken back to our application, we need to add following flags to intent.
            goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
            try {
                startActivity(goToMarket);
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (ActivityNotFoundException e) {
                startActivity(
                        new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="
                                + TApplication.applicationContext.getPackageName())));
            }
        }
    });
    //config twitter link
    AppCompatTextView txTwitterLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_twitter_telepathy);
    txTwitterLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                // If Twitter app is not installed, start browser.
                Uri twitterUri = Uri.parse("http://twitter.com/");
                startActivity(new Intent(Intent.ACTION_VIEW, twitterUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config privacy link
    AppCompatTextView txPrivacyLink = (AppCompatTextView) customLayout.findViewById(R.id.tx_privacy);
    txPrivacyLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                //open browser to navigate privacy link
                Uri privacyPolicyUri = Uri
                        .parse("https://github.com/atahani/telepathy-android/blob/master/LICENSE.md");
                startActivity(new Intent(Intent.ACTION_VIEW, privacyPolicyUri));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config report bug to open mail application and send bugs report
    AppCompatTextView txReportBug = (AppCompatTextView) customLayout.findViewById(R.id.tx_report_bug);
    txReportBug.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                final Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
                emailIntent.setType("plain/text");
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                        getString(R.string.label_report_bug_email_subject));
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailDeviceInformation());
                emailIntent.setData(Uri.parse("mailto:" + getString(R.string.telepathy_report_bug_email)));
                startActivity(Intent.createChooser(emailIntent,
                        getString(R.string.label_report_bug_choose_mail_app)));
                ((TelepathyBaseActivity) getActivity()).setAnimationOnStart();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    //config the about footer image view
    AboutFooterImageView footerImageView = (AboutFooterImageView) customLayout
            .findViewById(R.id.im_delete_user_account);
    footerImageView.setTouchOnImageViewEventListener(new AboutFooterImageView.touchOnImageViewEventListener() {
        @Override
        public void onDoubleTab() {
            try {
                //confirm account delete via alert dialog
                final AlertDialog.Builder confirmAccountDeleteDialog = new AlertDialog.Builder(getActivity());
                confirmAccountDeleteDialog.setTitle(getString(R.string.label_delete_user_account));
                confirmAccountDeleteDialog
                        .setMessage(getString(R.string.label_delete_user_account_description));
                confirmAccountDeleteDialog.setNegativeButton(getString(R.string.action_no), null);
                confirmAccountDeleteDialog.setPositiveButton(getString(R.string.action_yes),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //ok to delete account action
                                final ProgressDialog progressDialog = new ProgressDialog(getActivity());
                                progressDialog.setCancelable(false);
                                progressDialog.setCanceledOnTouchOutside(false);
                                progressDialog
                                        .setMessage(getString(R.string.re_action_on_deleting_user_account));
                                progressDialog.show();
                                TService tService = ((TelepathyBaseActivity) getActivity()).getTService();
                                tService.deleteUserAccount(new Callback<TOperationResultModel>() {
                                    @Override
                                    public void success(TOperationResultModel tOperationResultModel,
                                            Response response) {
                                        if (getActivity() != null && isAdded()) {
                                            //broad cast to close all of the realm  instance
                                            Intent intentToCloseRealm = new Intent(
                                                    Constants.TELEPATHY_BASE_ACTIVITY_INTENT_FILTER);
                                            intentToCloseRealm.putExtra(Constants.ACTION_TO_DO_PARAM,
                                                    Constants.CLOSE_REALM_DB);
                                            LocalBroadcastManager.getInstance(getActivity())
                                                    .sendBroadcastSync(intentToCloseRealm);
                                            mAppPreferenceTools.removeAllOfThePref();
                                            //                                 for sign out google first build GoogleAPIClient
                                            final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(
                                                    TApplication.applicationContext)
                                                            .addApi(Auth.GOOGLE_SIGN_IN_API).build();
                                            googleApiClient.connect();
                                            googleApiClient.registerConnectionCallbacks(
                                                    new GoogleApiClient.ConnectionCallbacks() {
                                                        @Override
                                                        public void onConnected(Bundle bundle) {
                                                            Auth.GoogleSignInApi.signOut(googleApiClient)
                                                                    .setResultCallback(
                                                                            new ResultCallback<Status>() {
                                                                                @Override
                                                                                public void onResult(
                                                                                        Status status) {
                                                                                    //also revoke google access
                                                                                    Auth.GoogleSignInApi
                                                                                            .revokeAccess(
                                                                                                    googleApiClient)
                                                                                            .setResultCallback(
                                                                                                    new ResultCallback<Status>() {
                                                                                                        @Override
                                                                                                        public void onResult(
                                                                                                                Status status) {
                                                                                                            progressDialog
                                                                                                                    .dismiss();
                                                                                                            TelepathyBaseActivity currentActivity = (TelepathyBaseActivity) TApplication.mCurrentActivityInApplication;
                                                                                                            if (currentActivity != null) {
                                                                                                                Intent intent = new Intent(
                                                                                                                        TApplication.applicationContext,
                                                                                                                        SignInActivity.class);
                                                                                                                intent.setFlags(
                                                                                                                        Intent.FLAG_ACTIVITY_CLEAR_TASK
                                                                                                                                | Intent.FLAG_ACTIVITY_NEW_TASK);
                                                                                                                currentActivity
                                                                                                                        .startActivity(
                                                                                                                                intent);
                                                                                                                currentActivity
                                                                                                                        .setAnimationOnStart();
                                                                                                                currentActivity
                                                                                                                        .finish();
                                                                                                            }
                                                                                                        }
                                                                                                    });
                                                                                }
                                                                            });
                                                        }

                                                        @Override
                                                        public void onConnectionSuspended(int i) {
                                                            //do nothing
                                                        }
                                                    });
                                        }
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        progressDialog.dismiss();
                                        if (getActivity() != null && isAdded()) {
                                            CommonFeedBack commonFeedBack = new CommonFeedBack(
                                                    getActivity().findViewById(android.R.id.content),
                                                    getActivity());
                                            commonFeedBack.checkCommonErrorAndBackUnCommonOne(error);
                                        }
                                    }
                                });
                            }
                        });
                confirmAccountDeleteDialog.show();
            } catch (Exception ex) {
                AndroidUtilities.processApplicationError(ex, true);
                if (isAdded() && getActivity() != null) {
                    Snackbar.make(getActivity().findViewById(android.R.id.content),
                            getString(R.string.re_action_internal_app_error), Snackbar.LENGTH_LONG).show();
                }
            }
        }
    });
    builder.setView(customLayout);
    return builder.create();
}

From source file:org.egov.android.view.activity.AllComplaintActivity.java

/**
 * The onResponse method will be invoked after the all complaint API call. onResponse methods
 * will contain the response.If the response has a status as 'success' then we have checked
 * whether the access token is valid or not.If the access token is invalid, redirect to login
 * page. If the access token is valid, the response contains the JSON object.
 * createdDate,complainantName,detail,crn,status values are retrieved from the response object
 * and store it to the variable then these values are set to the all complaint layout. call the
 * _addDownloadJobs method to display the complaint photo from the complaint photos directory on
 * the storage device. displays the All complaints list with the corresponding complaint image.
 * we have checked the pagination value.This value is retrieved from the api response if the
 * value is true then load more option will be displayed below the complaint list view.
 *//*from w  ww.  j  a v  a 2  s . c o m*/
@Override
public void onResponse(Event<ApiResponse> event) {
    String status = event.getData().getApiStatus().getStatus();
    String pagination = event.getData().getApiStatus().isPagination();
    String msg = event.getData().getApiStatus().getMessage();
    final ListView listView = (ListView) getActivity().findViewById(R.id.all_complaint_list);
    if (!toAppend) {
        listItem = new ArrayList<Complaint>();
    }
    if (status.equalsIgnoreCase("success")) {
        try {
            if (listItem.size() > 5) {
                listItem.remove(listItem.size() - 1);
            }
            JSONArray ja = new JSONArray(event.getData().getResponse().toString());
            Complaint item = null;
            isApiLoaded = true;
            if (ja.length() > 0) {
                ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.GONE);
                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = ja.getJSONObject(i);
                    item = new Complaint();
                    String userName = _getValue(jo, "complainantName");
                    item.setCreatedDate(_getValue(jo, "createdDate"));
                    item.setCreatedBy((userName.equals("")) ? _getValue(jo, "lastModifiedBy") : userName);
                    item.setDetails(_getValue(jo, "detail"));
                    item.setComplaintId(jo.getString("crn"));
                    item.setStatus(jo.getString("status"));
                    StorageManager sm = new StorageManager();
                    Object[] obj = sm.getStorageInfo(AllComplaintActivity.this.getActivity());
                    String complaintFolderName = obj[0].toString() + "/complaints/" + jo.getString("crn");

                    File complaintFolder = new File(complaintFolderName);
                    if (!complaintFolder.exists()) {
                        if (jo.getInt("supportDocsSize") == 0) {
                            item.setImagePath(
                                    complaintFolderName + File.separator + "photo_complaint_type.jpg");
                        } else {
                            item.setImagePath(complaintFolderName + File.separator + "photo_"
                                    + jo.getInt("supportDocsSize") + ".jpg");
                        }
                        sm.mkdirs(complaintFolderName);
                        _addDownloadJobs(complaintFolderName, jo);
                    } else {
                        item.setImagePath(complaintFolderName + File.separator + "photo_"
                                + complaintFolder.listFiles().length + ".jpg");
                    }
                    listItem.add(item);
                }

                if (listItem.size() > 5) {
                    listView.postDelayed(new Runnable() {
                        public void run() {
                            listView.setStackFromBottom(true);
                            listView.setSelection(listItem.size() - 8);
                        }
                    }, 0);
                }

                if (pagination.equals("true")) {
                    item = new Complaint();
                    listItem.add(item);
                }
                ServiceController.getInstance().startJobs();
                _displayListView(pagination.equals("true"));
            } else if (listItem.size() == 0) {
                ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.VISIBLE);
                _displayListView(false);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else {
        if (msg.matches(".*Invalid access token.*")) {
            _showMsg("Session expired");
            AndroidLibrary.getInstance().getSession().edit().putString("access_token", "").commit();
            Intent intent = new Intent(getActivity(), LoginActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            getActivity().startActivity(intent);
            getActivity().finish();
        } else {
            page = (page > 1) ? page - 1 : 1;
            _showMsg(msg);
        }
    }
}