当前位置: 首页>>代码示例>>Java>>正文


Java TaskStackBuilder.addNextIntentWithParentStack方法代码示例

本文整理汇总了Java中android.support.v4.app.TaskStackBuilder.addNextIntentWithParentStack方法的典型用法代码示例。如果您正苦于以下问题:Java TaskStackBuilder.addNextIntentWithParentStack方法的具体用法?Java TaskStackBuilder.addNextIntentWithParentStack怎么用?Java TaskStackBuilder.addNextIntentWithParentStack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.app.TaskStackBuilder的用法示例。


在下文中一共展示了TaskStackBuilder.addNextIntentWithParentStack方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: navigateUpOrBack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * This utility method handles Up navigation intents by searching for a parent activity and
 * navigating there if defined. When using this for an activity make sure to define both the
 * native parentActivity as well as the AppCompat one when supporting API levels less than 16.
 * when the activity has a single parent activity. If the activity doesn't have a single parent
 * activity then don't define one and this method will use back button functionality. If "Up"
 * functionality is still desired for activities without parents then use
 * {@code syntheticParentActivity} to define one dynamically.
 *
 * Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
 *       in Material Design guidelines.
 *
 * @param currentActivity Activity in use when navigate Up action occurred.
 * @param syntheticParentActivity Parent activity to use when one is not already configured.
 */
public static void navigateUpOrBack(Activity currentActivity,
                                    Class<? extends Activity> syntheticParentActivity) {
    // Retrieve parent activity from AndroidManifest.
    Intent intent = NavUtils.getParentActivityIntent(currentActivity);

    // Synthesize the parent activity when a natural one doesn't exist.
    if (intent == null && syntheticParentActivity != null) {
        try {
            intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (intent == null) {
        // No parent defined in manifest. This indicates the activity may be used by
        // in multiple flows throughout the app and doesn't have a strict parent. In
        // this case the navigation up button should act in the same manner as the
        // back button. This will result in users being forwarded back to other
        // applications if currentActivity was invoked from another application.
        currentActivity.onBackPressed();
    } else {
        if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
            // Need to synthesize a backstack since currentActivity was probably invoked by a
            // different app. The preserves the "Up" functionality within the app according to
            // the activity hierarchy defined in AndroidManifest.xml via parentActivity
            // attributes.
            TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
            builder.addNextIntentWithParentStack(intent);
            builder.startActivities();
        } else {
            // Navigate normally to the manifest defined "Up" activity.
            NavUtils.navigateUpTo(currentActivity, intent);
        }
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:52,代码来源:BaseActivity.java

示例2: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
private void createBackStack(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        startActivity(intent);
        finish();
    }
}
 
开发者ID:qqq3,项目名称:inventum,代码行数:11,代码来源:BaseActivity.java

示例3: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 * @param intent
 */
private void createBackStack(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        startActivity(intent);
        finish();
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:16,代码来源:BaseActivity.java

示例4: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
private void createBackStack(Intent intent) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    TaskStackBuilder builder = TaskStackBuilder.create(this);
    builder.addNextIntentWithParentStack(intent);
    builder.startActivities();
  } else {
    startActivity(intent);
    finish();
  }
}
 
开发者ID:g11x,项目名称:checklistapp,代码行数:11,代码来源:NavigationActivity.java

示例5: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent
 */
private void createBackStack(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        startActivity(intent);
        finish();
    }
}
 
开发者ID:SecUSo,项目名称:privacy-friendly-werewolf,代码行数:17,代码来源:BaseActivity.java

示例6: getPendingIntent

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
public static PendingIntent getPendingIntent(@NonNull Context context, @NonNull CharacterVO character, int id) {

        Intent intent = new Intent(context, CharacterActivity.class);
        intent.setAction(Integer.toString(id)); // Used to update all PendingIntent extras data for each widget
        intent.putExtra(EXTRA_CHARACTER, character);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntentWithParentStack(intent); // Return to MainActivity

        return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    }
 
开发者ID:andremion,项目名称:Villains-and-Heroes,代码行数:12,代码来源:CharacterActivity.java

示例7: navigateUpOrBack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * This utility method handles Up navigation intents by searching for a parent activity and
 * navigating there if defined. When using this for an activity make sure to define both the
 * native parentActivity as well as the AppCompat one when supporting API levels less than 16.
 * when the activity has a single parent activity. If the activity doesn't have a single parent
 * activity then don't define one and this method will use back button functionality. If "Up"
 * functionality is still desired for activities without parents then use
 * {@code syntheticParentActivity} to define one dynamically.
 * <p>
 * Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
 * in Material Design guidelines.
 *
 * @param currentActivity         Activity in use when navigate Up action occurred.
 * @param syntheticParentActivity Parent activity to use when one is not already configured.
 */
public static void navigateUpOrBack(Activity currentActivity,
                                    Class<? extends Activity> syntheticParentActivity) {
    // Retrieve parent activity from AndroidManifest.
    Intent intent = NavUtils.getParentActivityIntent(currentActivity);

    // Synthesize the parent activity when a natural one doesn't exist.
    if (intent == null && syntheticParentActivity != null) {
        try {
            intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (intent == null) {
        // No parent defined in manifest. This indicates the activity may be used by
        // in multiple flows throughout the app and doesn't have a strict parent. In
        // this case the navigation up button should act in the same manner as the
        // back button. This will result in users being forwarded back to other
        // applications if currentActivity was invoked from another application.
        currentActivity.onBackPressed();
    } else {
        if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
            // Need to synthesize a backstack since currentActivity was probably invoked by a
            // different app. The preserves the "Up" functionality within the app according to
            // the activity hierarchy defined in AndroidManifest.xml via parentActivity
            // attributes.
            TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
            builder.addNextIntentWithParentStack(intent);
            builder.startActivities();
        } else {
            // Navigate normally to the manifest defined "Up" activity.
            NavUtils.navigateUpTo(currentActivity, intent);
        }
    }
}
 
开发者ID:ashishbhandari,项目名称:RetailStore,代码行数:52,代码来源:BaseActivity.java

示例8: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 * @param intent
 */
private void createBackStack(Intent intent) {
    final Bundle bundle = ActivityOptionsCompat
            .makeCustomAnimation(this, android.R.anim.fade_in, android.R.anim.fade_out)
            .toBundle();

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    builder.addNextIntentWithParentStack(intent);
    builder.startActivities(bundle);
}
 
开发者ID:Hotmart-Org,项目名称:zum-android,代码行数:15,代码来源:BaseActivity.java

示例9: createBackStack

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 *
 * @param intent
 */
private void createBackStack(Intent intent)
{
    if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN )
    {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    }
    else
    {
        startActivity(intent);
        finish();
    }
}
 
开发者ID:SecUSo,项目名称:privacy-friendly-shopping-list,代码行数:21,代码来源:BaseActivity.java

示例10: buildAndShowDailyNotification

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
private void buildAndShowDailyNotification(HashMap<String, Integer> merchantCouponCountMap) {
    String contentTitle = context.getString(R.string.coupons_expiring_today);
    String baseContextText = "%d coupons from %d merchants";
    String baseNotificationLine = "%d coupons from %s";
    if (Build.VERSION.SDK_INT < N) {
        contentTitle = context.getString(R.string.app_name);
        baseContextText = "%d coupons from %d merchants expires today";
        baseNotificationLine = "%d coupons from %s";
    }

    int numMerchants = merchantCouponCountMap.size();
    int numTotalCoupons = 0;
    NotificationCompat.InboxStyle notificationStyle = new NotificationCompat.InboxStyle();
    notificationStyle.setBigContentTitle(contentTitle);
    for (Map.Entry<String, Integer> entry : merchantCouponCountMap.entrySet()) {
        numTotalCoupons += entry.getValue();
        notificationStyle.addLine(String.format(baseNotificationLine, entry.getValue(), entry.getKey()));
    }
    String contentText = String.format(Locale.ENGLISH, baseContextText, numTotalCoupons, numMerchants);

    // Do not show notification if there are no coupons expiring today
    if (numTotalCoupons == 0) {
        notificationStyle = null;
        return;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setContentTitle(contentTitle)
            .setContentText(contentText)
            .setStyle(notificationStyle)
            .setLargeIcon(Utilities.getBitmap(context, R.drawable.ic_notifications_24dp))
            .setSmallIcon(smallIconId)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true);

    Intent contentIntent = new Intent(context, ContainerActivity.class);
    contentIntent.putExtra(Constants.BUNDLE_EXTRA_FRAGMENT_TYPE, Constants.FragmentType.NOTIFICATION_FRAGMENT);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntentWithParentStack(contentIntent);
    PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
    );
    builder.setContentIntent(contentPendingIntent);

    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(context);
    String ringtone = sharedPreferences.getString(SettingsFragment.KEY_NOTIFICATION_RINGTONE, "");
    boolean shouldVibrate = sharedPreferences.getBoolean(SettingsFragment.KEY_NOTIFICATION_VIBRATE, true);
    if (ringtone.length() == 0) {
        builder.setSound(null);
    } else {
        try {
            builder.setSound(Uri.parse(ringtone));
        } catch (NullPointerException e) {
            e.printStackTrace();
            builder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
        }
    }
    if (shouldVibrate) {
        builder.setDefaults(Notification.DEFAULT_VIBRATE);
    }

    NotificationManagerCompat.from(context).cancel(TAG, DAILY_NOTIFICATION_ID);
    NotificationManagerCompat.from(context).notify(
            TAG,
            DAILY_NOTIFICATION_ID,
            builder.build()
    );
}
 
开发者ID:darsh2,项目名称:CouponsTracker,代码行数:71,代码来源:CouponsTrackerNotification.java

示例11: buildNotification

import android.support.v4.app.TaskStackBuilder; //导入方法依赖的package包/类
public static Notification buildNotification(Context context, String title, String text, Bitmap bitmap) {

        String contentTitle = "Roku";
        String contentText = "";

        if (title != null) {
            contentTitle = title;
        }

        if (text != null) {
            contentText = text;
        }

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntentWithParentStack(new Intent(context, MainActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        PendingIntent contentIntent = stackBuilder.getPendingIntent((int) System.currentTimeMillis(), 0);

        NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();

        NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
                .setContentTitle(contentTitle)
                .setContentText(contentText)
                .setContentIntent(contentIntent)
                .setWhen(0)
                .setSmallIcon(R.mipmap.ic_launcher);

        if (bitmap != null) {
            builder.setLargeIcon(bitmap);
        }

        builder.addAction(GenerateActionCompat(context, R.drawable.ic_action_rewind, "Previous", 0, KeypressKeyValues.REV));
        builder.addAction(GenerateActionCompat(context, R.drawable.ic_action_pause, "Pause", 1, KeypressKeyValues.PLAY));
        builder.addAction(GenerateActionCompat(context, R.drawable.ic_action_fast_forward, "Next", 2, KeypressKeyValues.FWD));

        style.setShowActionsInCompactView(0, 1, 2);
        style.setShowCancelButton(true);

        builder.setStyle(style);

        return builder.build();
    }
 
开发者ID:wseemann,项目名称:RoMote,代码行数:43,代码来源:NotificationUtils.java


注:本文中的android.support.v4.app.TaskStackBuilder.addNextIntentWithParentStack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。