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.android.pingme.PingService.java

private void issueNotification(Intent intent, String msg) {
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    // Sets up the Snooze and Dismiss action buttons that will appear in the
    // expanded view of the notification.
    Intent dismissIntent = new Intent(this, PingService.class);
    dismissIntent.setAction(CommonConstants.ACTION_DISMISS);
    PendingIntent piDismiss = PendingIntent.getService(this, 0, dismissIntent, 0);

    Intent snoozeIntent = new Intent(this, PingService.class);
    snoozeIntent.setAction(CommonConstants.ACTION_SNOOZE);
    PendingIntent piSnooze = PendingIntent.getService(this, 0, snoozeIntent, 0);

    // Constructs the Builder object.
    builder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_stat_notification)
            .setContentTitle(getString(R.string.notification)).setContentText(getString(R.string.ping))
            .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            /*//from www  .j a v  a 2 s  . c o  m
             * Sets the big view "big text" style and supplies the
             * text (the user's reminder message) that will be displayed
             * in the detail area of the expanded notification.
             * These calls are ignored by the support library for
             * pre-4.1 devices.
             */
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .addAction(R.drawable.ic_stat_dismiss, getString(R.string.dismiss), piDismiss)
            .addAction(R.drawable.ic_stat_snooze, getString(R.string.snooze), piSnooze);

    /*
     * Clicking the notification itself displays ResultActivity, which provides
     * UI for snoozing or dismissing the notification.
     * This is available through either the normal view or big view.
     */
    Intent resultIntent = new Intent(this, ResultActivity.class);
    resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg);
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);
    startTimer(mMillis);
}

From source file:com.sukenda.todoapp.module.task.tasks.TasksActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  w w  w .ja  v  a 2  s .  co m*/
        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);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    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:com.asburymotors.android.disneysocal.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();
        }/* w  ww  .j  a  v  a 2s. c o  m*/

        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;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.zyascend.RecompileToDo.view.tasks.TasksActivity.java

private void setupDrawerContent(NavigationView navView) {
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  w w w  . j a v a  2  s  .  c  o m*/
        public boolean onNavigationItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.list_navigation_menu_item:
                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;
            }

            item.setChecked(true);
            drawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:codepath.watsiapp.activities.BaseFragmentActivity.java

private void logout() {
    prefs.clearAll();//from   ww w.java  2  s . c om
    ParseUser.logOut();

    // FLAG_ACTIVITY_CLEAR_TASK only works on API 11, so if the user
    // logs out on older devices, we'll just exit.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Intent intent = new Intent(BaseFragmentActivity.this, WatsiMainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } else {
        finish();
    }
}

From source file:com.samknows.measurement.util.LoginHelper.java

public static void openMainScreen(Activity acc) {
    Intent intent = new Intent(acc, SamKnowsAggregateStatViewerActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    acc.startActivity(intent);// w w w  . ja v a 2s . c o  m
    acc.finish();
}

From source file:com.mohammedsazidalrashid.android.sunshine.DetailsFragment.java

private Intent createShareForecastIntent() {
    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    shareIntent.setType("text/plain");
    shareIntent.putExtra(Intent.EXTRA_TEXT,
            MainActivity.bundleForFragments.getString(ForecastFragment.EXTRA_FORECAST)
                    + FORECAST_SHARE_HASHTAG);

    return shareIntent;
}

From source file:com.sspai.dkjt.service.GenerateFrameService.java

@Override
public void doneImage(final Uri imageUri) {
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override//from  ww  w. j a va  2s.c  om
        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(ConfigString.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());
}

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

@Override
public void onSuccessLogin(User user) {
    Intent intent = new Intent(this, TombolActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);//w ww. j  a  v a 2 s .com
}

From source file:com.example.team04adventure.View.AllStoriesListSwipe.java

/**
 * onResume method, simply assigns sets the adapter and a listener to listen
 * to user selections of story items.//from w w  w . j av a2 s  .  co  m
 */

public void onResume() {
    super.onResume();
    stories = new ArrayList<Story>();
    Integer index = Integer.valueOf(-6);
    try {
        stories = new JSONparser().execute(index).get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

    allAdapter = new StoryListAdapter(getActivity(), stories);
    storyListView.setAdapter(allAdapter);
    storyListView.setOnItemClickListener(new OnItemClickListener() {

        /**
         * When a story is selected, bundle the necessary vars into an
         * intent and begin the new activity that will bring the user to the
         * online story's intro page.
         * 
         * @param AdapterView
         *            , View, int, long
         * @return void
         */
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            mDialog = new ProgressDialog(v.getContext());
            mDialog.setMessage("Please wait...");
            mDialog.show();
            Story s = (Story) storyListView.getItemAtPosition(position);
            Intent intent = new Intent(getActivity(), OnlineStoryIntro.class);
            intent.putExtra("id", s.getId());
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            startActivity(intent);
        }

    });

    randomButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // goToStory(id);
            if (stories.size() > 0) {
                mDialog = new ProgressDialog(arg0.getContext());
                mDialog.setMessage("Opening Random Story...");
                mDialog.show();
                Story s = (Story) stories.get(chooseRandom());
                Intent intent = new Intent(getActivity(), OnlineStoryIntro.class);
                intent.putExtra("id", s.getId());
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
            } else {
                String validun = "No Online Stories!";
                Toast.makeText(arg0.getContext(), validun, Toast.LENGTH_LONG).show();
            }

        }
    });

}