當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。