Example usage for android.support.v4.content IntentCompat FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.support.v4.content IntentCompat FLAG_ACTIVITY_CLEAR_TASK

Introduction

In this page you can find the example usage for android.support.v4.content IntentCompat FLAG_ACTIVITY_CLEAR_TASK.

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

To view the source code for android.support.v4.content IntentCompat 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:augsburg.se.alltagsguide.utilities.ui.BasePageWebViewLanguageActivity.java

@SuppressWarnings("unchecked")
private void setPageFromSerializable(Serializable serializable) {
    try {//from w  w  w . j av  a  2s. c  o m
        if (serializable != null) {
            setPage((T) serializable);
        } else {
            Intent intent = new Intent(BasePageWebViewLanguageActivity.this, OverviewActivity.class);
            intent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish();
        }
    } catch (ClassCastException e) {
        Ln.e(e);
        throw new IllegalStateException("ARG_INFO has to be of type (? extends Page)");
    }
}

From source file:augsburg.se.alltagsguide.utilities.ui.BaseActivity.java

protected void restartActivity() {
    Intent intent = getIntent();
    intent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    finish();
    startActivity(intent);
}

From source file:com.ichi2.anki.services.NotificationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Timber.i("NotificationService: OnStartCommand");

    Context context = getApplicationContext();
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(context);
    int minCardsDue = Integer.parseInt(preferences.getString("minimumCardsDueForNotification", "25"));
    int dueCardsCount = WidgetStatus.fetchDue(context);
    if (dueCardsCount >= minCardsDue) {
        // Build basic notification
        String cardsDueText = getString(R.string.widget_minimum_cards_due_notification_ticker_text,
                dueCardsCount);/*from w w w.ja va2s.c o  m*/
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_notify)
                .setColor(ContextCompat.getColor(context, R.color.material_light_blue_700))
                .setContentTitle(cardsDueText).setTicker(cardsDueText);
        // Enable vibrate and blink if set in preferences
        if (preferences.getBoolean("widgetVibrate", false)) {
            builder.setVibrate(new long[] { 1000, 1000, 1000 });
        }
        if (preferences.getBoolean("widgetBlink", false)) {
            builder.setLights(Color.BLUE, 1000, 1000);
        }
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, DeckPicker.class);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(WIDGET_NOTIFY_ID, builder.build());
    } else {
        // Cancel the existing notification, if any.
        mNotificationManager.cancel(WIDGET_NOTIFY_ID);
    }
    return START_STICKY;
}

From source file:com.rorlig.babyapp.ui.fragment.InjectableFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.action_settings:
        startActivity(new Intent(getActivity(), PrefsActivity.class));
        return true;
    case R.id.action_licenses:
        startActivity(new Intent(getActivity(), LicenseActivity.class));
        return true;

    case R.id.action_tutorial:
        Intent tutorialIntent = new Intent(getActivity(), TutorialActivity.class);
        //                Bundle args = new Bundle();
        //                args.putBoolean("fromLauncher", false);
        tutorialIntent.putExtra("fromLauncher", false);
        startActivity(tutorialIntent);/* www  .  j a va2  s . com*/
        return true;

    case R.id.action_logout:
        ParseUser.logOutInBackground();
        //                new LogOutCallback() {
        //                    @Override
        //                    public void done(ParseException e) {
        Log.d(TAG, "logging out from parse");
        clearUserInfo();
        Intent intent = new Intent(getActivity().getApplicationContext(), LoginActivity.class);
        intent.setFlags(
                intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        return true;
    //                    }
    //                });
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.thatkawaiiguy.meleehandbook.activity.AppSettingsActivity.java

@Override
public void onBackPressed() {
    if (restart) {
        super.onBackPressed();
        final Intent intent = IntentCompat
                .makeMainActivity(new ComponentName(AppSettingsActivity.this, MainActivity.class));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);/*  w ww  .j a  v  a 2 s.co  m*/
    } else
        super.onBackPressed();
}

From source file:io.github.sin3hz.fastjumper.sample.MainActivity.java

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        Intent intent = new Intent(MainActivity.this, MainActivity.class);
        intent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);/*  ww w . j  a va 2s  .c  o m*/
        overridePendingTransition(0, 0);
    }
}

From source file:in.codehex.facilis.ForgotPasswordActivity.java

/**
 * Send request to the server to reset the password of the user.
 *
 * @param email the email address of the user.
 */// www  . j  av  a  2s . co  m
private void processForgotPass(String email) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put(Config.KEY_API_EMAIL, email);
    } catch (JSONException e) {
        // TODO: remove toast
        Toast.makeText(ForgotPasswordActivity.this, "Error occurred while generating data - " + e.getMessage(),
                Toast.LENGTH_SHORT).show();
    }

    showProgressDialog();
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Config.API_FORGOT_PASS,
            jsonObject, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    hideProgressDialog();
                    mIntent = new Intent(ForgotPasswordActivity.this, LoginActivity.class);
                    mIntent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(mIntent);
                    Toast.makeText(ForgotPasswordActivity.this,
                            "Password reset link has been sent to your mail", Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hideProgressDialog();
                    NetworkResponse response = error.networkResponse;
                    // TODO: remove toast
                    if (response.statusCode == 400)
                        Toast.makeText(ForgotPasswordActivity.this,
                                "Error processing your request! Try again later!", Toast.LENGTH_SHORT).show();
                }
            });

    AppController.getInstance().addToRequestQueue(jsonObjectRequest, "forgot_pass");
}

From source file:de.grobox.liberario.fragments.PrefsFragment.java

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    if (key.equals(Preferences.THEME)) {
        ListPreference themePref = (ListPreference) findPreference(key);
        themePref.setSummary(themePref.getEntry());

        getActivity().finish();//from  w  ww  . j  a  v a2  s .  c o  m
        final Intent intent = getActivity().getIntent();
        intent.setAction(MainActivity.ACTION_SETTINGS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
        getActivity().startActivity(intent);

        // switch back to this fragment, because it doesn't work the first time where fragment is not yet found
        final Intent intent2 = new Intent(getActivity(), MainActivity.class);
        intent2.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent2.setAction(MainActivity.ACTION_SETTINGS);
        startActivity(intent2);
    }
}

From source file:in.codehex.facilis.MainActivity.java

/**
 * Display an alert when logout icon is clicked.
 *///from  w w  w.ja v a2 s  .  co  m
private void showAlertLogout() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle("Logout");
    alertDialog.setMessage("Are you sure you want to logout?");
    alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // TODO: send logout request to API
            userPreferences.edit().clear().commit();
            mIntent = new Intent(MainActivity.this, LoginActivity.class);
            mIntent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(mIntent);
        }
    });
    alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alertDialog.show();
}

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

/**
 * Send request to the server to process login and fetch user token.
 *
 * @param email  email address of the user.
 * @param pass   password submitted by the user.
 * @param client wifi mac address of the user's device
 *//* w w w .  j a v  a2  s. c om*/
private void processLogin(final String email, final String pass, final String client) {
    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put(Config.KEY_API_USERNAME, email);
        jsonObject.put(Config.KEY_API_PASSWORD, pass);
        jsonObject.put(Config.KEY_API_CLIENT, client);
    } catch (JSONException e) {
        // TODO: remove toast
        Toast.makeText(LoginActivity.this, "Error occurred while generating data - " + e.getMessage(),
                Toast.LENGTH_SHORT).show();
    }

    showProgressDialog();
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Config.API_LOGIN,
            jsonObject, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    hideProgressDialog();
                    try {
                        String firstName = response.getString(Config.KEY_API_FIRST_NAME);
                        String lastName = response.getString(Config.KEY_API_LAST_NAME);
                        int userId = response.getInt(Config.KEY_API_USER_ID);
                        int companyId = response.getInt(Config.KEY_PREF_COMPANY_ID);
                        boolean creditStatus = response.getBoolean(Config.KEY_PREF_CREDIT_STATUS);
                        int role = response.getInt(Config.KEY_API_ROLE);
                        String token = response.getString(Config.KEY_API_TOKEN);
                        String userImage = response.getString(Config.KEY_API_USER_IMAGE);

                        SharedPreferences.Editor editor = userPreferences.edit();
                        editor.putString(Config.KEY_PREF_FIRST_NAME, firstName);
                        editor.putString(Config.KEY_PREF_LAST_NAME, lastName);
                        editor.putInt(Config.KEY_PREF_USER_ID, userId);
                        editor.putInt(Config.KEY_PREF_COMPANY_ID, companyId);
                        editor.putBoolean(Config.KEY_PREF_CREDIT_STATUS, creditStatus);
                        editor.putInt(Config.KEY_PREF_ROLE, role);
                        editor.putString(Config.KEY_PREF_TOKEN, token);
                        editor.putString(Config.KEY_USER_IMAGE, userImage);
                        editor.apply();

                        mIntent = new Intent(LoginActivity.this, MainActivity.class);
                        mIntent.addFlags(IntentCompat.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(mIntent);
                    } catch (JSONException e) {
                        // TODO: remove toast
                        Toast.makeText(LoginActivity.this,
                                "Error occurred while parsing data - " + e.getMessage(), Toast.LENGTH_SHORT)
                                .show();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    hideProgressDialog();
                    NetworkResponse response = error.networkResponse;
                    try {
                        byte[] data = response.data;
                        String mError = new String(data);
                        JSONObject errorObject = new JSONObject(mError);
                        JSONArray nonFieldErrors = errorObject.getJSONArray(Config.KEY_API_NON_FIELD_ERRORS);
                        String errorData = nonFieldErrors.getString(0);
                        Toast.makeText(LoginActivity.this, errorData, Toast.LENGTH_SHORT).show();
                    } catch (JSONException e) {
                        // TODO: remove toast
                        Toast.makeText(LoginActivity.this,
                                "Error occurred while parsing data - " + e.getMessage(), Toast.LENGTH_SHORT)
                                .show();
                    } catch (NullPointerException e) {
                        // TODO: remove toast
                        Toast.makeText(LoginActivity.this, "Network error - " + e.getMessage(),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            });

    AppController.getInstance().addToRequestQueue(jsonObjectRequest, "login");
}