Example usage for android.support.v4.app TaskStackBuilder from

List of usage examples for android.support.v4.app TaskStackBuilder from

Introduction

In this page you can find the example usage for android.support.v4.app TaskStackBuilder from.

Prototype

public static TaskStackBuilder from(Context context) 

Source Link

Document

Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.

Usage

From source file:com.example.android.appnavigation.app.InterstitialMessageActivity.java

public void onViewContent(View v) {
    TaskStackBuilder.from(this).addParentStack(ContentViewActivity.class)
            .addNextIntent(new Intent(this, ContentViewActivity.class).putExtra(ContentViewActivity.EXTRA_TEXT,
                    "From Interstitial Notification"))
            .startActivities();// w  w  w.  ja  v a 2 s .co m
    finish();
}

From source file:com.example.android.appnavigation.app.NotificationsActivity.java

public void onPostDirect(View v) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker("Direct Notification")
            .setSmallIcon(android.R.drawable.stat_notify_chat).setContentTitle("Direct Notification")
            .setContentText("This will open the content viewer").setAutoCancel(true)
            .setContentIntent(TaskStackBuilder.from(this).addParentStack(ContentViewActivity.class)
                    .addNextIntent(new Intent(this, ContentViewActivity.class)
                            .putExtra(ContentViewActivity.EXTRA_TEXT, "From Notification"))
                    .getPendingIntent(0, 0));
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify("direct_tag", R.id.direct_notification, builder.getNotification());
}

From source file:com.example.android.appnavigation.app.ContentViewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = NavUtils.getParentActivityIntent(this);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.from(this).addParentStack(this).startActivities();
            finish();/*ww w.jav a 2 s  .c o m*/
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.nuvolect.securesuite.util.NotificationUtil.java

/**
 * Push a notification to the notification area.
 * Up to 6 previous notifications will be shown as small text.
 * @param ctx/*from  ww w  .  j ava  2s.c o m*/
 * @param title
  */
public static void pushNotification(Context ctx, String title) {

    Class<?> nextActivity = ContactListActivity.class;

    // Make sure duplicates are not added to the list
    if (smallTextHistory.size() > 0 && smallTextHistory.get(0).contentEquals(title))
        return;

    if (smallTextHistory.size() > 6) { // Only keep last six

        for (int i = smallTextHistory.size() - 1; i > 5; --i)
            smallTextHistory.remove(i);
    }

    Resources res = ctx.getResources();
    Bitmap largeIcon = BitmapFactory.decodeResource(res, CConst.LARGE_ICON);

    // When using proper icon sizes this scaling code is not required
    //      int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
    //      int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
    //      largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false);

    @SuppressWarnings("deprecation")
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setTicker(title)
            .setContentTitle(title).setSmallIcon(CConst.SMALL_ICON).setLargeIcon(largeIcon).setAutoCancel(false)
            .setNumber(++runningTotal).setAutoCancel(true)
            .setContentIntent(TaskStackBuilder.from(ctx).addParentStack(nextActivity)
                    .addNextIntent(new Intent(ctx, nextActivity)).getPendingIntent(0, 0));

    // Use the previous notification as small text, if there is one
    if (smallTextHistory.size() > 0)
        builder.setContentText(smallTextHistory.get(0));

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    inboxStyle.setBigContentTitle(title);
    builder.setStyle(inboxStyle);

    for (String textItem : smallTextHistory)
        inboxStyle.addLine(textItem);

    NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(NOTIFICATION_ID, inboxStyle.build());

    // Save the title as the top of the small text list for next notification
    smallTextHistory.add(0, title);
}

From source file:com.tencent.stt.DatCheckActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.about:
        Toast.makeText(this, "about", Toast.LENGTH_SHORT).show();
        break;/*from w w w. j av  a2  s  . com*/

    case R.id.settings:
        Toast.makeText(this, "setting", Toast.LENGTH_SHORT).show();
        break;

    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }

    return true;
}

From source file:com.ame.armymax.SettingsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        setTitle("Everything");
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            TaskStackBuilder.from(this).addNextIntent(upIntent).startActivities();
            finish();//from w ww.j  a  v a 2 s  . co  m
        } else {
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.marijaradisavljevic.bla.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, MainActivityMarijs.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();/*from  w w w .  j a  va  2 s.c  om*/
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.app.v1.iresto.DemoSwipeTab2Activity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, DemoSwipeTabActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//from  w  w  w  .  j av  a  2  s  . c  o  m
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.handsfree.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, LaunchTutorial.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();//w w w.j a  v a2  s .c o m
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.agilemessage.ameffectivenavigation.CollectionDemoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This is called when the Home (Up) button is pressed in the action bar.
        // Create a simple intent that starts the hierarchical parent activity and
        // use NavUtils in the Support Package to ensure proper handling of Up.
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    // If there are ancestor activities, they should be added here.
                    .addNextIntent(upIntent).startActivities();
            finish();// w  w w . j a  v a2 s  . c o m
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}