本文整理汇总了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);
}
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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();
}
}
示例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()
);
}
示例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();
}