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.saarang.samples.apps.iosched.gcm.command.NotificationCommand.java

private void processCommand(Context context, NotificationCommandModel command) {
    // Check format
    if (!"1.0.00".equals(command.format)) {
        LogUtils.LOGW(TAG, "GCM notification command has unrecognized format: " + command.format);
        return;/* w w w  .j av a  2 s . c  o m*/
    }

    // Check app version
    if (!TextUtils.isEmpty(command.minVersion) || !TextUtils.isEmpty(command.maxVersion)) {
        LogUtils.LOGD(TAG, "Command has version range.");
        int minVersion = 0;
        int maxVersion = Integer.MAX_VALUE;
        try {
            if (!TextUtils.isEmpty(command.minVersion)) {
                minVersion = Integer.parseInt(command.minVersion);
            }
            if (!TextUtils.isEmpty(command.maxVersion)) {
                maxVersion = Integer.parseInt(command.maxVersion);
            }
            LogUtils.LOGD(TAG, "Version range: " + minVersion + " - " + maxVersion);
            PackageInfo pinfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
            LogUtils.LOGD(TAG, "My version code: " + pinfo.versionCode);
            if (pinfo.versionCode < minVersion) {
                LogUtils.LOGD(TAG, "Skipping command because our version is too old, " + pinfo.versionCode
                        + " < " + minVersion);
                return;
            }
            if (pinfo.versionCode > maxVersion) {
                LogUtils.LOGD(TAG, "Skipping command because our version is too new, " + pinfo.versionCode
                        + " > " + maxVersion);
                return;
            }
        } catch (NumberFormatException ex) {
            LogUtils.LOGE(TAG,
                    "Version spec badly formatted: min=" + command.minVersion + ", max=" + command.maxVersion);
            return;
        } catch (Exception ex) {
            LogUtils.LOGE(TAG, "Unexpected problem doing version check.", ex);
            return;
        }
    }

    // Check if we are the right audience
    LogUtils.LOGD(TAG, "Checking audience: " + command.audience);
    if ("remote".equals(command.audience)) {
        if (PrefUtils.isAttendeeAtVenue(context)) {
            LogUtils.LOGD(TAG, "Ignoring notification because audience is remote and attendee is on-site");
            return;
        } else {
            LogUtils.LOGD(TAG, "Relevant (attendee is remote).");
        }
    } else if ("local".equals(command.audience)) {
        if (!PrefUtils.isAttendeeAtVenue(context)) {
            LogUtils.LOGD(TAG, "Ignoring notification because audience is on-site and attendee is remote.");
            return;
        } else {
            LogUtils.LOGD(TAG, "Relevant (attendee is local).");
        }
    } else if ("all".equals(command.audience)) {
        LogUtils.LOGD(TAG, "Relevant (audience is 'all').");
    } else {
        LogUtils.LOGE(TAG, "Invalid audience on GCM notification command: " + command.audience);
        return;
    }

    // Check if it expired
    Date expiry = command.expiry == null ? null : TimeUtils.parseTimestamp(command.expiry);
    if (expiry == null) {
        LogUtils.LOGW(TAG, "Failed to parse expiry field of GCM notification command: " + command.expiry);
        return;
    } else if (expiry.getTime() < UIUtils.getCurrentTime(context)) {
        LogUtils.LOGW(TAG, "Got expired GCM notification command. Expiry: " + expiry.toString());
        return;
    } else {
        LogUtils.LOGD(TAG, "Message is still valid (expiry is in the future: " + expiry.toString() + ")");
    }

    // decide the intent that will be fired when the user clicks the notification
    Intent intent;
    if (TextUtils.isEmpty(command.dialogText)) {
        // notification leads directly to the URL, no dialog
        if (TextUtils.isEmpty(command.url)) {
            intent = new Intent(context, MyScheduleActivity.class)
                    .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        } else {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(command.url));
        }
    } else {
        // use a dialog
        intent = new Intent(context, MyScheduleActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_TITLE,
                command.dialogTitle == null ? "" : command.dialogTitle);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_MESSAGE,
                command.dialogText == null ? "" : command.dialogText);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_YES,
                command.dialogYes == null ? "OK" : command.dialogYes);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_NO, command.dialogNo == null ? "" : command.dialogNo);
        intent.putExtra(MyScheduleActivity.EXTRA_DIALOG_URL, command.url == null ? "" : command.url);
    }

    final String title = TextUtils.isEmpty(command.title)
            ? context.getString(com.saarang.samples.apps.iosched.R.string.app_name)
            : command.title;
    final String message = TextUtils.isEmpty(command.message) ? "" : command.message;

    // fire the notification
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification)
                    .setTicker(command.message).setContentTitle(title).setContentText(message)
                    //.setColor(context.getResources().getColor(R.color.theme_primary))
                    // Note: setColor() is available in the support lib v21+.
                    // We commented it out because we want the source to compile 
                    // against support lib v20. If you are using support lib
                    // v21 or above on Android L, uncomment this line.
                    .setContentIntent(
                            PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT))
                    .setAutoCancel(true).build());
}

From source file:com.nutsuser.ridersdomain.activities.LiveforDream.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    Intent intent = new Intent(LiveforDream.this, MainScreenActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("MainScreenResponse", "OPEN");
    startActivity(intent);// w w w .  j a  v a 2s .c o m
    finish();
}

From source file:com.example.ishita.administrativeapp.AttendantActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_logout) {

        personalData.SaveData(false);/*from  w w  w . j  a  v  a2s. co  m*/
        Intent launch_logout = new Intent(AttendantActivity.this, MainActivity.class);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        launch_logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(launch_logout);
        finish();

    } /*else if(id==R.id.password) {
      Intent in = new Intent(getApplicationContext(), ChangePassword.class);
      startActivity(in);
              
      }*/
    return true;
}

From source file:org.disrupted.rumble.network.NetworkCoordinator.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    synchronized (lock) {
        if (intent == null)
            return START_STICKY;

        if (intent.getAction().equals(ACTION_START_FOREGROUND)) {
            Log.d(TAG, "Received Start Foreground Intent ");

            serviceHandler.post(new Runnable() {
                @Override/*w  w  w.j a v a  2 s . c  o m*/
                public void run() {
                    // start networking from a new thread to avoid performing network
                    // related operation from the UI thread
                    startNetworking();
                }
            });

            Intent notificationIntent = new Intent(this, RoutingActivity.class);
            notificationIntent.setAction(ACTION_MAIN_ACTION);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

            NotificationCompat.Builder notification = showNotification("Rumble", "Rumble Started",
                    "Rumble Started", R.drawable.small_icon, pendingIntent, true);

            startForeground(FOREGROUND_SERVICE_ID, notification.build());
        }
    }

    return START_STICKY;
}

From source file:com.wolkabout.hexiwear.activity.MainActivity.java

@OptionsItem
void signOut() {
    credentials.clear();
    LoginActivity_.intent(this).flags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK).start();
    finish();
}

From source file:org.chromium.chrome.browser.notifications.NotificationUIManager.java

/**
 * Launches the notifications preferences screen. If the received intent indicates it came
 * from the gear button on a flipped notification, this launches the site specific preferences
 * screen.//w w w  .ja  v  a2 s  .  c  o  m
 *
 * @param context The context that received the intent.
 * @param incomingIntent The received intent.
 */
public static void launchNotificationPreferences(Context context, Intent incomingIntent) {
    // Use the application context because it lives longer. When using he given context, it
    // may be stopped before the preferences intent is handled.
    Context applicationContext = context.getApplicationContext();

    // If we can read an origin from the intent, use it to open the settings screen for that
    // origin.
    String origin = getOriginFromTag(
            incomingIntent.getStringExtra(NotificationConstants.EXTRA_NOTIFICATION_TAG));
    boolean launchSingleWebsitePreferences = origin != null;

    String fragmentName = launchSingleWebsitePreferences ? SingleWebsitePreferences.class.getName()
            : SingleCategoryPreferences.class.getName();
    Intent preferencesIntent = PreferencesLauncher.createIntentForSettingsPage(applicationContext,
            fragmentName);

    Bundle fragmentArguments;
    if (launchSingleWebsitePreferences) {
        // Record that the user has clicked on the [Site Settings] button.
        RecordUserAction.record("Notifications.ShowSiteSettings");

        // All preferences for a specific origin.
        fragmentArguments = SingleWebsitePreferences.createFragmentArgsForSite(origin);
    } else {
        // Notification preferences for all origins.
        fragmentArguments = new Bundle();
        fragmentArguments.putString(SingleCategoryPreferences.EXTRA_CATEGORY,
                SiteSettingsCategory.CATEGORY_NOTIFICATIONS);
        fragmentArguments.putString(SingleCategoryPreferences.EXTRA_TITLE,
                applicationContext.getResources().getString(R.string.push_notifications_permission_title));
    }
    preferencesIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, fragmentArguments);

    // We need to ensure that no existing preference tasks are being re-used in order for the
    // new activity to appear on top.
    preferencesIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    applicationContext.startActivity(preferencesIntent);
}

From source file:foundme.uniroma2.it.professore.Connection.java

@Override
protected void onPostExecute(String result[]) {
    if (result[0].equalsIgnoreCase(Variables_it.NO_INTERNET)) {
        if (enProgressDialog)
            caricamento.dismiss();//from   w  w  w  .j ava  2s .c o  m
        Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
        return;
    }
    if (enProgressDialog) {
        caricamento.dismiss();
        if (!returnMessage.equalsIgnoreCase(Variables_it.NAME)
                || result[0].equalsIgnoreCase(Variables_it.ERROR)) {
            if (!returnMessage.equalsIgnoreCase("") && !returnMessage.equalsIgnoreCase(Variables_it.NO_MSG)) {
                Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
            }
        }
    }
    if (returnMessage.equalsIgnoreCase(Variables_it.NO_MSG)) {
        ReadMessageActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.DEL_MSG_OK)) {
        try {
            ReadMessageActivity.getMsg(toDo, false);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else if (toDo.equalsIgnoreCase(Variables_it.GET)) {
        HomeActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.SEND_MSG_OK)
            && toDo.equalsIgnoreCase(Variables_it.MSGS)) {
        ((Activity) context).finish();
    } else if (returnMessage.equalsIgnoreCase(Variables_it.NAME) && toDo.equalsIgnoreCase(Variables_it.LOG)
            && !result[0].equalsIgnoreCase(Variables_it.ERROR)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, LoginActivity.getuser());
        SPEditor.setPass(pref, LoginActivity.getpass());
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra(Variables_it.TAG, LoginActivity.gettag());
        intent.putExtra(Variables_it.NAME, result[0]);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.FINISH)) {
        ((Activity) context).finish();
        try {
            HomeActivity.getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.CHANGEP)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setPass(pref, ChangePswActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.REGIS)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, RegistrationActivity.getmail());
        SPEditor.setPass(pref, RegistrationActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.DELACC)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.delete(pref);
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }

    else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.HOME)) {
        try {
            HomeActivity.getCourse(false);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.miz.mizuu.ShowDetails.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        if (getIntent().getExtras().getBoolean("isFromWidget")) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK
                    | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            i.putExtra("startup", String.valueOf(Main.SHOWS));
            i.setClass(getApplicationContext(), Main.class);
            startActivity(i);/*w w  w.j  ava 2s. c  o  m*/
        }
        finish();

        return true;
    case R.id.menuDeleteShow:
        deleteShow();
        break;
    case R.id.change_cover:
        searchCover();
        break;
    case R.id.identify_show:
        identifyShow();
        break;
    }
    return false;
}

From source file:com.example.android.popularmovies.fragments.MovieTrailersFragment.java

private Intent getShareIntent() {
    String msg = getString(R.string.easter_egg);
    if (!mTrailerAdapter.getList().isEmpty()) {
        for (Trailer trailer : mTrailerAdapter.getList()) {
            if (trailer.getSite().toLowerCase().equals(NetworkUtils.YOUTUBE)) {
                msg = NetworkUtils.getYoutubeUrl(trailer.getKey());
                break;
            }/*  w  w  w  .  j  a v a  2 s.c  o  m*/
        }

    }

    Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity()).setType("text/plain").setText(msg)
            .getIntent();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    } else {
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    return shareIntent;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_credit_card);

    //Set action bar fields
    getSupportActionBar().setTitle(PiggateUser.getEmail());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    //Views/*from w  w w  .j  a  v  a 2  s  .  co m*/
    EditCardNumber = (EditText) findViewById(R.id.cardNumber);
    EditCVC = (EditText) findViewById(R.id.CVC);
    SpinnerYear = (Spinner) findViewById(R.id.spinerYear);
    SpinnerMonth = (Spinner) findViewById(R.id.spinerMonth);
    validate = (Button) findViewById(R.id.buttonValidate);
    buttonBuy = (Button) findViewById(R.id.buttonBuy);
    buttonCancel = (Button) findViewById(R.id.buttonCancel);
    headerLayout = (LinearLayout) findViewById(R.id.headerLayout);
    cardlayout = (LinearLayout) findViewById(R.id.cardlayout);
    buylayout = (LinearLayout) findViewById(R.id.buyLayout);
    image = (SmartImageView) findViewById(R.id.offerImage2);

    //Animations
    slidetoLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidetoleft);
    slidetoRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidetoright);
    slidefromRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidefromright);
    slidefromLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidefromleft);

    //Validation Error AlertDialog
    errorDialog = new AlertDialog.Builder(buyOfferActivity.this).create();
    errorDialog.setTitle("Validation error");
    errorDialog.setMessage("The credit card is not valid");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //Network Error AlertDialog
    networkDialog = new AlertDialog.Builder(this).create();
    networkDialog.setTitle("Network error");
    networkDialog.setMessage("Network is not working");
    networkDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    image.setImageUrl(getIntent().getExtras().getString("offerImgURL")); //Set the offer image from URL
    //(Provisional) set the default fields of the credit card
    EditCardNumber.setText("4242424242424242");
    EditCVC.setText("123");

    piggate = new Piggate(this); //Initialize Piggate Object

    //OnClick listener for the validate button
    validate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Validate the credit card with Stripe
            if (checkInternetConnection() == true) {
                // Credit card for testing: ("4242-4242-4242-4242", 12, 2016, "123")
                if (piggate.validateCard(EditCardNumber.getText().toString(),
                        Integer.parseInt(SpinnerMonth.getSelectedItem().toString()),
                        Integer.parseInt(SpinnerYear.getSelectedItem().toString()),
                        EditCVC.getText().toString(), "pk_test_BN86VnxiMBHkZtzPmpykc56g", //Stripe test. Will be returned by requests in next release
                        buyOfferActivity.this, "Validating", "Wait while the credit card is validated")) {
                    openBuyLayout();
                } else
                    errorDialog.show();
            } else {
                networkDialog.show();
            }
        }
    });

    //OnClick listener for the buy button
    buttonBuy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Do the buy request to the server
            RequestParams params = new RequestParams();
            //Get the latest credit card Stripe token, amount to pay, type of coin and ID
            params.put("stripeToken", piggate.get_creditCards().get(piggate.get_creditCards().size() - 1)
                    .getTokenID().toString());
            params.put("amount", getIntent().getExtras().getString("offerPrice"));
            params.put("offerID", getIntent().getExtras().getString("offerID"));
            params.put("currency", getIntent().getExtras().getString("offerCurrency"));

            //Loading payment ProgressDialog
            loadingDialog = ProgressDialog.show(v.getContext(), "Payment", "Wait while the payment is finished",
                    true);

            //Do the buy request to the server (The server do the payment with Stripe)
            piggate.RequestBuy(params).setListenerRequest(new Piggate.PiggateCallBack() {

                //onComplete method for JSONObject
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                    loadingDialog.dismiss();

                    //Go back to the offer list passing the offer attributes (to exchange)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("offerID", getIntent().getExtras().getString("offerID"));
                    slideactivity.putExtra("offerName", getIntent().getExtras().getString("offerName"));
                    slideactivity.putExtra("offerDescription",
                            getIntent().getExtras().getString("offerDescription"));
                    slideactivity.putExtra("payment", true);
                    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);
                }

                //onError method for JSONObject
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {

                    //Show an error and go back to the credit card
                    loadingDialog.dismiss();
                    //Go back to the offer list with the variable payment set to false (payment error)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("payment", false);
                    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);
                }

                //onComplete method for JSONArray
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                    loadingDialog.dismiss();

                    //Go back to the offer list passing the offer attributes (to exchange)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("offerID", getIntent().getExtras().getString("offerID"));
                    slideactivity.putExtra("offerName", getIntent().getExtras().getString("offerName"));
                    slideactivity.putExtra("offerDescription",
                            getIntent().getExtras().getString("offerDescription"));
                    slideactivity.putExtra("payment", true);
                    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);
                }

                //onError method for JSONArray (Show an error and go back to the credit card)
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {

                    //Show an error and go back to the credit card
                    loadingDialog.dismiss();
                    //Go back to the offer list with the variable payment set to false (payment error)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("payment", false);
                    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);
                }
            }).exec();
        }
    });

    //OnClick listener for the cancel button (Go back to the credit card)
    buttonCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closeBuyLayout();
        }
    });
}