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.miz.service.MoveFilesService.java

@Override
protected void onHandleIntent(Intent intent) {

    // Setup up notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setColor(getResources().getColor(R.color.color_primary));
    builder.setSmallIcon(R.drawable.ic_sync_white_24dp);
    builder.setTicker(getString(R.string.movingDataFiles));
    builder.setContentTitle(getString(R.string.movingDataFiles));
    builder.setContentText(getString(R.string.movingDataFilesDescription));
    builder.setOngoing(true);/*from   w  w  w  .ja v a 2  s  . c  o  m*/
    builder.setOnlyAlertOnce(true);

    // Build notification
    Notification updateNotification = builder.build();

    // Show the notification
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(5, updateNotification);

    // Tell the system that this is an ongoing notification, so it shouldn't be killed
    startForeground(5, updateNotification);

    File[] listFiles;
    String name = "";

    File oldDataFolder = FileUtils.getOldDataFolder();
    if (oldDataFolder.listFiles() != null) {
        listFiles = oldDataFolder.listFiles();
        int count = listFiles.length;
        for (int i = 0; i < count; i++) {
            name = listFiles[i].getName();
            if (!listFiles[i].isDirectory()) {
                if (name.endsWith("_bg.jpg")) { // Movie backdrop
                    movieBackdrop(listFiles[i]);
                } else if (name.endsWith("_tvbg.jpg")) { // TV show backdrop
                    tvShowBackdrop(listFiles[i]);
                } else if (name.contains("_S") && name.contains("E") && name.endsWith(".jpg")) { // Episode photo
                    episodePhoto(listFiles[i]);
                } else { // Collection cover art
                    movieThumb(listFiles[i]);
                }
                listFiles[i].delete();
            }
        }
    }

    File oldMovieThumbs = new File(FileUtils.getOldDataFolder() + "/movie-thumbs");
    if (oldMovieThumbs.exists() && oldMovieThumbs.listFiles() != null) {
        listFiles = oldMovieThumbs.listFiles();
        int count = listFiles.length;
        for (int i = 0; i < count; i++) {
            movieThumb(listFiles[i]);
            listFiles[i].delete();
        }
    }

    File oldTvShowThumbs = new File(FileUtils.getOldDataFolder() + "/tvshows-thumbs");
    if (oldTvShowThumbs.exists() && oldTvShowThumbs.listFiles() != null) {
        listFiles = oldTvShowThumbs.listFiles();
        int count = listFiles.length;
        for (int i = 0; i < count; i++) {
            tvShowThumb(listFiles[i]);
            listFiles[i].delete();
        }
    }

    // Delete the old data folder
    FileUtils.deleteRecursive(oldDataFolder, true);

    Intent i = new Intent(this, SplashScreen.class);
    i.addFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(i);
}

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *///w w w .  j  a  va  2s .  co  m
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void prepareNotification() {
    Intent intent = new Intent(this, Splash.class);
    intent.putExtra("NotificationMessage", bigMsg);
    //intent.putExtra("notificationId",notificationId);
    //intent.putExtra("showDetails",true);
    //intent.putExtra("isActive",isRunning());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:id.zelory.tanipedia.activity.KomoditasActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_komoditas);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);/*from  w  w  w .ja  v  a  2s.  com*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Harga Komoditas");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(3).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(KomoditasActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                intent = new Intent(KomoditasActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                intent = new Intent(KomoditasActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                return true;
            case R.id.logout:
                PrefUtils.simpanString(KomoditasActivity.this, "nama", null);
                intent = new Intent(KomoditasActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(KomoditasActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    imageHeader = (ImageView) findViewById(R.id.header);
    imageHeader.setVisibility(View.GONE);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.example.android.xyztouristattractions.ui.DetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Some small additions to handle "up" navigation correctly
        Intent upIntent = NavUtils.getParentActivityIntent(getActivity());
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        // Check if up activity needs to be created (usually when
        // detail screen is opened from a notification or from the
        // Wearable app
        if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getActivity().isTaskRoot()) {

            // Synthesize parent stack
            TaskStackBuilder.create(getActivity()).addNextIntentWithParentStack(upIntent).startActivities();
        }/*from w w w  .j av  a 2 s  .  c om*/

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            // On Lollipop+ we finish so to run the nice animation
            getActivity().finishAfterTransition();
            return true;
        }

        // Otherwise let the system handle navigating "up"
        return false;
    case R.id.map:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(
                Uri.parse(Constants.MAPS_INTENT_URI + Uri.encode(mAttraction.name + ", " + mAttraction.city)));
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:ca.six.unittestapp.todo.tasks.TasksActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  w  w  w . j  av a 2 s.  c  om*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                // Do nothing, we're already on that screen
                break;
            case R.id.statistics_navigation_menu_item:
                Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:id.zelory.tanipedia.activity.BeritaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_berita);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);

    setSupportActionBar(toolbar);//  www  .j  a  v  a 2 s  .c o  m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Berita Terbaru");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(1).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(BeritaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                return true;
            case R.id.tanya:
                intent = new Intent(BeritaActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                intent = new Intent(BeritaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(BeritaActivity.this, "nama", null);
                intent = new Intent(BeritaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(BeritaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });
    imageHeader = (ImageView) findViewById(R.id.header);
    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.example.administrator.myapplication2._2_exercise._2_End._2_EndMain.java

@Override
public void onBackPressed() {
    //Set Class to Top of App and no history
    Intent launchNextActivity;/*from  w w w .  j  ava 2 s .  co m*/
    launchNextActivity = new Intent(this, Main.class);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    launchNextActivity.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(launchNextActivity);
}

From source file:com.feedhenry.armark.MainActivity.java

private void goLogin() {
    Intent intent = new Intent(this, Loggin.class);

    // AADIMOS banderas que nos permite limpiar el recorrido anterior, cuando presionemos atras no nos devuelve al MainActivity.
    intent.addFlags(//from ww w  .  ja v  a 2  s.c o  m
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

}

From source file:com.itime.team.itime.services.ITimeGcmListenerService.java

/**
 * If received message is OTHER_DEVICE_LOGIN, start CheckLoginActivity
 * @param data GCM message received./*from   w w  w.java2s.com*/
 */
private void checkLogout(Bundle data) {
    if (data.getString("itime_message_type", "").equals("OTHER_DEVICE_LOGIN")) {
        updateUserTable(this);
        Intent logoutIntent = new Intent(this, CheckLoginActivity.class);
        logoutIntent.putExtra("username", User.ID);
        Log.i(getClass().getSimpleName(), User.ID);

        // This service will initialize User class with User ID as empty. If app is started, User
        // ID will be set a value. It could be used as an indicator for whether app is running.
        if (!User.ID.isEmpty()) {
            // Important!!!
            // startActivity from a service must add FLAG_ACTIVITY_NEW_TASK
            // FLAG_ACTIVITY_CLEAR_TASK will clear the previous task
            logoutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(logoutIntent);
            Log.i(getClass().getSimpleName(), "checklogout");
        }
    }
}

From source file:com.f2prateek.dfg.core.GenerateFrameService.java

@Override
public void doneImage(final Uri imageUri) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override/*  w  ww .  j a  v  a2s.  co m*/
        public void run() {
            bus.post(new Events.SingleImageProcessed(device, imageUri));
        }
    });

    // Create the intent to let the user share the image
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("image/png");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
    Intent chooserIntent = Intent.createChooser(sharingIntent, null);
    chooserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationBuilder.addAction(R.drawable.ic_action_share, getResources().getString(R.string.share),
            PendingIntent.getActivity(this, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    // Create the intent to let the user rate the app
    Intent rateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(AppConstants.MARKET_URL));
    notificationBuilder.addAction(R.drawable.ic_action_rate, getResources().getString(R.string.rate),
            PendingIntent.getActivity(this, 0, rateIntent, PendingIntent.FLAG_CANCEL_CURRENT));

    // Create the intent to show the screenshot in gallery
    Intent launchIntent = new Intent(Intent.ACTION_VIEW);
    launchIntent.setDataAndType(imageUri, "image/png");
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationBuilder.setContentTitle(resources.getString(R.string.screenshot_saved_title))
            .setContentText(resources.getString(R.string.single_screenshot_saved, device.name()))
            .setContentIntent(PendingIntent.getActivity(this, 0, launchIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, false).setAutoCancel(true);

    notificationManager.notify(DFG_NOTIFICATION_ID, notificationBuilder.build());
}