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.yeshwanthemani.billpayementapp.HomeActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from ww  w.j a v  a2s . co  m*/
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // Handle the camera action
        takePicture();
    } else if (id == R.id.nav_account) {
        Intent i = new Intent(this, Account.class);
        startActivity(i);

    } else if (id == R.id.nav_offers) {

    } else if (id == R.id.nav_about) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    } else if (id == R.id.nav_signout) {
        Intent intent = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
    }

    //   DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    // drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:in.rab.ordboken.Ordboken.java

public boolean onOptionsItemSelected(Activity activity, MenuItem item) {
    if (item.getItemId() == R.id.menu_logout) {
        updateCreds("", "");
        mNeClient.logout();/*from  ww w  .  j av  a2 s .c o  m*/

        SharedPreferences.Editor ed = mPrefs.edit();
        ed.putBoolean("loggedIn", false);
        ed.putString("username", "");
        ed.putString("password", "");
        ed.commit();

        Intent intent = new Intent(mContext, LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(intent);

        activity.finish();

        return true;
    } else if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(activity);
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities();
        } else {
            NavUtils.navigateUpFromSameTask(activity);
        }
        return true;
    }

    return false;
}

From source file:com.geekandroid.sdk.base.BaseActivity.java

public void startActivityClearTask(Class<?> cls) {
    Intent intent = new Intent(this, cls);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);/*from  ww w.  jav a 2  s  .co  m*/
}

From source file:io.samsungsami.example.SAMInBLEws.SAMIDeviceActivity.java

private void startLoginActivity() {
    SAMISession.getInstance().reset();//from   www.  j a  v  a  2  s .  c  om
    Intent activityIntent = new Intent(this, SAMILoginActivity.class);
    activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(activityIntent);
    finish();
}

From source file:com.velli.passwordmanager.ActivityLockScreen.java

private void startActivityMain() {
    ApplicationBase.setActivityStatus(ApplicationBase.ACTIVITY_MAIN, ApplicationBase.STATUS_STARTING_ACTIVITY,
            false);//from   www.ja va2s. c om
    final Intent i = new Intent(this, ActivityMain.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(i);
    finish();
}

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

@Override
public void onEscortClosed(Escort escort) {
    AlertDialog alertDialog = new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher)
            .setTitle(reporter.getName().split(" ")[0] + " telah sampai.")
            .setMessage(reporter.getName().split(" ")[0]
                    + " telah sampai pada tujuan dengan selamat, terimakasih atas partisipasi anda.")
            .setPositiveButton("OK", (dialog, which) -> {
                showLoading();/*from   w  w w . j av a2 s.co  m*/
                User currentUser = CacheManager.pluck().getCurrentUser();
                Map<String, Object> data = new HashMap<>();
                data.put("users/" + currentUser.getUserId() + "/status/", "SIAP");
                FirebaseApi.pluck().getApi().updateChildren(data, (firebaseError, firebase) -> {
                    if (firebaseError != null) {
                        Timber.e(firebaseError.getMessage());
                        showError("Gagal mengirimkan data konfirmasi!");
                        dismissLoading();
                    } else {
                        currentUser.setStatus(User.Status.SIAP);
                        CacheManager.pluck().cacheCurrentUser(currentUser);
                        StateManager.pluck().setState(StateManager.pluck().recoveryState());
                        Intent intent = new Intent(this, TombolActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                        dismissLoading();
                    }
                });
                dialog.dismiss();
            }).setCancelable(false).show();

    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
    alertDialog.show();
}

From source file:com.oakesville.mythling.MediaListActivity.java

protected void handleEmptyMediaList() {
    // go to main
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);//from w ww  .j  av  a  2  s  .  c om
    finish();
}

From source file:org.creativecommons.thelist.activities.StartActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    mContext = this;
    mSharedPref = new SharedPreferencesMethods(mContext);
    mCurrentUser = new ListUser(StartActivity.this);
    am = AccountManager.get(getBaseContext());

    //Google Analytics Tracker
    ((ListApplication) getApplication()).getTracker(ListApplication.TrackerName.GLOBAL_TRACKER);

    //Create App SharedPreferences
    SharedPreferences sharedPref = mContext.getSharedPreferences(SharedPreferencesMethods.APP_PREFERENCES_KEY,
            Context.MODE_PRIVATE);

    //TODO: add google analytics opt-in
    //Display Google Analytics Message
    if (!(mSharedPref.getGaMessageViewed())) {
        //The beta version of this app uses google analytics message
        MessageHelper mh = new MessageHelper(mContext);
        mh.showDialog(mContext, "The List Beta Uses Google Analytics",
                "Hey just a heads up that "
                        + "were using Google Analytics to help us learn how to make the app better. "
                        + "We dont collect personal info!");
        mSharedPref.setMessageViewed();// www. j a va 2s.  co m
    }

    //UI Elements
    mFrameLayout = (FrameLayout) findViewById(R.id.fragment_container);
    mStartButton = (Button) findViewById(R.id.startButton);
    mAccountButton = (Button) findViewById(R.id.accountButton);
    mTermsLink = (TextView) findViewById(R.id.cc_logo_label);

    //Im new to the list?
    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Load explainerFragment
            getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, explainerFragment)
                    .commit();
            mFrameLayout.setClickable(true);
        }
    }); //StartButton ClickListener

    //I already have an account?
    mAccountButton.setOnClickListener(new View.OnClickListener() {
        //If you have accounts > show picker; if not, show login
        @Override
        public void onClick(View v) {
            Account availableAccounts[] = am.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);

            //TODO: switch getAuthed: login to first account if there if only one, if there is more than more go to accountPicker
            if (availableAccounts.length > 1) {
                mCurrentUser.showAccountPicker(new ListUser.AuthCallback() {
                    @Override
                    public void onSuccess(String authtoken) {
                        Log.d(TAG, "I have an account > Got an authtoken");
                        //TODO: is this actually needed?
                        Intent intent = new Intent(StartActivity.this, MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                    }
                });
            } else {
                mCurrentUser.getAuthed(new ListUser.AuthCallback() {
                    @Override
                    public void onSuccess(String authtoken) {
                        Log.d(TAG, "I have an account + I re-authenticated > Got an authtoken");
                        //TODO: is this actually needed?
                        Intent intent = new Intent(StartActivity.this, MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        startActivity(intent);
                    }
                });
            }
        }
    }); //accountButton

    //Enable links
    if (mTermsLink != null) {
        mTermsLink.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

From source file:com.raffaele.squarecash4glass.CVVConfirmActivity.java

private void doLaunchTransactionCompleted() {
    // startActivity(new Intent(this,
    // ContactActivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK));
    startActivity(new Intent(this, TransactionCompleted.class).addFlags(
            Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));

}

From source file:samples.piggate.com.piggateInfoDemo.InfoActivity.java

public void backButton() {
    Intent slideactivity = new Intent(InfoActivity.this, Activity_Logged.class);
    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);
}