Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TOP.

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:at.fhooe.mcm.saap.facebook.HelloFacebookSampleActivity.java

private void onClickShowActivities() {
    Intent intent = new Intent(this, ExecutionListActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

    startActivity(intent);//  w  ww. jav a 2  s.co  m
    //      performPublish(PendingAction.POST_PHOTO,
    //            canPresentShareDialogWithPhotos);
}

From source file:org.sirimangalo.meditationplus.ActivityMain.java

private void showLogin() {
    doingLogin = true;//from   w ww.j a v a2  s.  c o  m
    Intent i = new Intent(this, ActivityLogin.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(i, LOGIN_CODE);
}

From source file:abanoubm.dayra.main.Main.java

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    if (requestCode == FOLDER_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Intent intent = new Intent(Intent.ACTION_VIEW).addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.setDataAndType(Uri.fromFile(new File(Utility.getDayraFolder())), "*/*");
            startActivity(intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
        }//from   www  .  j  a v  a  2s . c o  m

    } else if (requestCode == IMPORT_REQUEST) {
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
            importDB();

    }
}

From source file:com.oo58.game.texaspoker.AppActivity.java

public void innerRestart() {
    final Intent intent = getPackageManager().getLaunchIntentForPackage(getPackageName());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);/*from w w  w  . j a  v a2s .c  om*/

}

From source file:com.pvo.activity.MainFragmentActivity.java

@Override
public void onBackPressed() {
    if (fragmentStack.size() > 1) {
        System.out.println("--> On back press if condition <---");
        FragmentTransaction ft = fragmentManager.beginTransaction();
        if (ft != null) {
            fragmentStack.lastElement().onPause();
            ft.remove(fragmentStack.pop());
            Fragment lastFragment = fragmentStack.lastElement();
            lastFragment.onResume();/*from  w ww.  ja v a  2  s.  c  om*/
            ft.show(lastFragment);
            ft.commit();
        }
    } else {
        System.out.println("--> On back press else condition <---");
        Fragment visible = getVisibleFragment();
        if (visible instanceof ZNotificationMainFragment) {
            clearStoreData();
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else {
            redirectToNotificaiton();
        }
    }
}

From source file:it.feio.android.omninotes.async.DataBackupIntentService.java

/**
 * Creation of notification on operations completed
 *//*from   w  ww. j a  v a2  s. c o m*/
private void createNotification(Intent intent, Context mContext, String title, String message, File backupDir) {

    // The behavior differs depending on intent action
    Intent intentLaunch;
    if (DataBackupIntentService.ACTION_DATA_IMPORT.equals(intent.getAction())
            || DataBackupIntentService.ACTION_DATA_IMPORT_SPRINGPAD.equals(intent.getAction())) {
        intentLaunch = new Intent(mContext, MainActivity.class);
        intentLaunch.setAction(Constants.ACTION_RESTART_APP);
    } else {
        intentLaunch = new Intent();
    }
    // Add this bundle to the intent
    intentLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intentLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // Creates the PendingIntent
    PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, intentLaunch,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationsHelper mNotificationsHelper = new NotificationsHelper(mContext);
    mNotificationsHelper.createNotification(R.drawable.ic_content_save_white_24dp, title, notifyIntent)
            .setMessage(message).setRingtone(prefs.getString("settings_notification_ringtone", null))
            .setLedActive();
    if (prefs.getBoolean("settings_notification_vibration", true))
        mNotificationsHelper.setVibration();
    mNotificationsHelper.show();
}

From source file:com.safecell.ManageProfile_Activity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {

        if (callingActivity.equals("SettingScreenActivity")) {
            Intent homeScreen = new Intent(ManageProfile_Activity.this, SettingScreenActivity.class);
            homeScreen.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(homeScreen);//from  w w  w.  j a  v  a  2s . c  o m
            finish();
        } else if (callingActivity.equals("AccountActivity")) {
            Intent homeScreen = new Intent(ManageProfile_Activity.this, AccountActivity.class);
            homeScreen.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            homeScreen.putExtra("Account_Activity_Calling", "From manage profile activity");
            startActivity(homeScreen);
            finish();
        }
    }
    return false;

}

From source file:azad.hallaji.farzad.com.masirezendegi.ExplainMoshaver.java

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.nav_marakez) {
        Intent intent = new Intent(this, PageMarakez.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        //intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        finish();/* w ww  .j av a2s  . c o  m*/
        startActivity(intent);
    } else if (id == R.id.nav_profile) {
        Intent intent = new Intent(this, PageVirayesh.class);
        finish();
        startActivity(intent);
    } else if (id == R.id.nav_login) {
        Intent intent = new Intent(this, PageLogin.class);
        finish();
        startActivity(intent);
    } else if (id == R.id.nav_moshaverin) {
        Intent intent = new Intent(this, PageMoshaverin.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        finish();
        startActivity(intent);
    } else if (id == R.id.nav_porseshha) {
        Intent intent = new Intent(this, PagePorseshha.class);
        finish();
        startActivity(intent);
    } else if (id == R.id.nav_logout) {
        Intent intent = new Intent(this, PageLogout.class);
        finish();
        startActivity(intent);
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.END);
    return true;

}

From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java

/**
 * Abre o anexo pela URI do arquivo anexado para visualizao.
 * @param mUri//from   w ww  .ja  va2  s  .co  m
 */
private void abrirAnexo(Uri mUri) {
    String extension = FilenameUtils.getExtension(AndroidFileUtils.getPath(AnexoCadastroActivity.this, mUri));
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        MimeTypeMap mime = MimeTypeMap.getSingleton();

        String type = mime.getMimeTypeFromExtension(extension);

        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(mUri, type);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplicationContext().startActivity(intent);

    } catch (ActivityNotFoundException e) {
        new ErrorAlert(AnexoCadastroActivity.this, getResources().getString(R.string.app_name),
                "No foi encontrado nenhum aplicativo nesse aparelho que suporte abrir a extenso '"
                        + extension
                        + "', entre em contato com a equipe de Suporte para resolver esse problema.").show();
    } catch (Exception e) {
        new ErrorAlert(AnexoCadastroActivity.this, getResources().getString(R.string.app_name),
                "No foi possvel abrir o anexo " + anexo.getId() + ". " + e.getMessage()).show();
        e.printStackTrace();
    }
}

From source file:git.lawpavilionprime.auth._Login.java

static void LoadSession() {

    //TODO: uncomment this
    if (SIGN_IN_TYPE == LOGGED_OUT_USER_TYPE) {
        // Restart the activity
        Intent intent = new Intent(mContext, _Login.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mContext.startActivity(intent);/*from www. j a v a2  s  . c  o m*/
    } else if (SIGN_IN_TYPE == NEW_USER_TYPE) {
        //Integer maxDeviceCount = Integer.valueOf(max_device_count)
        Integer nDeviceCount = Integer.valueOf(device_count);
        Integer maxDeviceCount = 1;

        if (nDeviceCount < maxDeviceCount) {
            txtProgressMessage.setText("Finishing...");
            mProgressBar.setVisibility(View.VISIBLE);

            //Send the Device ID..
            AsyncManager.runBackgroundTask(new _AsyncSendDeviceId());

            SharedPreferences sharedPref = mContext.getSharedPreferences(_Login.class.getSimpleName(),
                    Context.MODE_PRIVATE);
            String gcmID = sharedPref.getString("registration_id", null);

            if (gcmID == null) {
                //generate n send GCM ID
                new RegisterApp(mContext).execute();
                Log.d("--DEBUG--", "not available");
            } else {
                //Send GCM ID
                Log.d("--DEBUG---CHECK", gcmID);
                new RegisterApp(mContext).execute();
            }
        } else {
            //notify of max usage of device
            //drop table..
            dbAdapter.open(DB_NAME);
            dbAdapter.executeQuery("DROP TABLE " + dbAdapter.TABLE_NAME);
            dbAdapter.close();
            Toast.makeText(mContext, "Maximum number of device reached", Toast.LENGTH_SHORT).show();
        }
    } else {
        Toast.makeText(mContext, "Error", Toast.LENGTH_SHORT).show();
    }
}