类android.app.TaskStackBuilder源码实例Demo

下面列出了怎么用android.app.TaskStackBuilder的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: itag   文件: ITagsService.java
static Notification createForegroundNotification(Context context) {
    createForegroundNotificationChannel(context);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, FOREGROUND_CHANNEL_ID);
    builder
            .setTicker(null)
            .setSmallIcon(R.drawable.app)
            .setContentTitle(context.getString(R.string.service_in_background))
            .setContentText(context.getString(R.string.service_description));
    Intent intent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(pendingIntent);
    return builder.build();
}
 
源代码2 项目: shortbread   文件: ShortbreadGenerated.java
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    if (shortcuts == null) {
        List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
        List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
        enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
                .setShortLabel("Short label")
                .setIntents(TaskStackBuilder.create(context)
                        .addNextIntent(new Intent(Intent.ACTION_VIEW))
                        .getIntents())
                .setRank(0)
                .build());

        shortcuts = Arrays.asList(enabledShortcuts, disabledShortcuts);
    }

    return shortcuts;
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel("SHORT_LABEL")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(BackStackShortcutActivity.class)
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity1.class))
                    .addNextIntent(new Intent(Intent.ACTION_VIEW).setClass(context, EmptyActivity2.class))
                    .addNextIntent(new Intent(context, BackStackShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, SimpleShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(SimpleShortcutActivity.class)
                    .addNextIntent(new Intent(context, SimpleShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel("SHORT_LABEL")
            .setLongLabel("LONG_LABEL")
            .setIcon(Icon.createWithResource(context, 123))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(AdvancedShortcutActivity.class)
                    .addNextIntent(new Intent(context, AdvancedShortcutActivity.class)
                            .setAction("ACTION"))
                    .getIntents())
            .setRank(1)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity2.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity2.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity2.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod1"))
                    .getIntents())
            .setRank(0)
            .build());
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID_2")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TwoMethodShortcutsActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TwoMethodShortcutsActivity.class)
                    .addNextIntent(new Intent(context, TwoMethodShortcutsActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod2"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
源代码9 项目: YCNotification   文件: ReminderReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "ReminderReceiver");
    //Calendar now = GregorianCalendar.getInstance();
    Notification.Builder mBuilder = new Notification.Builder(context)
                    .setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("广播接受者标题,小杨")
                    .setContentText("广播接受者内容,扯犊子")
                    .setAutoCancel(true);

    Log.i(TAG, "onReceive: intent" + intent.getClass().getName());
    Intent resultIntent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    //将该Activity添加为栈顶
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    NotificationManager mNotificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, mBuilder.build());
}
 
private void showAppNotification() {
    mBuilder.setSmallIcon(R.drawable.ic_notification);
    mBuilder.setLargeIcon(mIcon);
    Intent resultIntent = new Intent(this, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    startForeground(SERVICE_IDENTIFIER, mBuilder.build());
}
 
源代码11 项目: AndroidSamples   文件: StageService.java
private void showNotification() {
    // 创建通知栏
    Notification.Builder mBuilder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.img_tm)
            .setContentTitle("标题")
            .setContentText("文本");
    // 点击跳转到Activity
    Intent intent = new Intent(this, MainActivity.class);
    // 创建任务栈
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
    // 设置跳转
    mBuilder.setContentIntent(pendingIntent);

    // 获取通知服务
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // 构建通知
    Notification notification = mBuilder.build();
    // 显示通知
    nm.notify(0,notification);

    // 启动前台服务
    startForeground(0,notification);
}
 
private void sendNotification() {
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(this)
                    .setContentTitle("Beacon Reference Application")
                    .setContentText("An beacon is nearby.")
                    .setSmallIcon(R.drawable.ic_launcher);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);
    NotificationManager notificationManager =
            (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, builder.build());
}
 
源代码13 项目: catnut   文件: ComposeTweetService.java
private void fallback(Draft draft, String error) {
	draft.createAt = System.currentTimeMillis();
	getContentResolver().insert(CatnutProvider.parse(Draft.MULTIPLE), Draft.METADATA.convert(draft));
	mBuilder.setContentTitle(getString(R.string.post_fail))
			.setContentText(error)
			.setTicker(getText(R.string.post_fail))
			.setProgress(0, 0, false);

	// 添加fallback跳转
	Intent resultIntent = SingleFragmentActivity.getIntent(this, SingleFragmentActivity.DRAFT);

	TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
	taskStackBuilder.addParentStack(SingleFragmentActivity.class);
	taskStackBuilder.addNextIntent(resultIntent);
	PendingIntent resultPendingIntent =
			taskStackBuilder.getPendingIntent(
					ID,
					PendingIntent.FLAG_UPDATE_CURRENT
			);
	mBuilder.setContentIntent(resultPendingIntent)
			.setAutoCancel(true);
	mNotifyManager.notify(ID, mBuilder.build());
}
 
源代码14 项目: xDrip   文件: ForegroundServiceStarter.java
private Notification notification() {
    Intent intent = new Intent(mContext, Home.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
    stackBuilder.addParentStack(Home.class);
    stackBuilder.addNextIntent(intent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );

    NotificationCompat.Builder b=new NotificationCompat.Builder(mService);
    b.setOngoing(true);
    b.setCategory(Notification.CATEGORY_SERVICE);
    // Hide this notification "below the fold" on L+
    b.setPriority(Notification.PRIORITY_MIN);
    // Don't show this notification on the lock screen on L+
    b.setVisibility(Notification.VISIBILITY_SECRET);
    b.setContentTitle("xDrip is Running")
            .setContentText("xDrip Data collection service is running.")
            .setSmallIcon(R.drawable.ic_action_communication_invert_colors_on);
    b.setContentIntent(resultPendingIntent);
    return(b.build());
}
 
源代码15 项目: Readily   文件: SettingsActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case android.R.id.home:
			Intent upIntent = NavUtils.getParentActivityIntent(this);
			if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
				TaskStackBuilder.create(this)
						.addNextIntentWithParentStack(upIntent)
						.startActivities();
			} else {
				upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(upIntent);
				finish();
			}
			return true;
	}
	return super.onOptionsItemSelected(item);
}
 
源代码16 项目: wear-os-samples   文件: 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();
            }

            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);
}
 
源代码17 项目: ShadowsocksRR   文件: ScannerActivity.java
private void navigateUp() {
    Intent intent = getParentActivityIntent();
    if (shouldUpRecreateTask(intent) || isTaskRoot()) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities();
    } else {
        finish();
    }
}
 
源代码18 项目: Maying   文件: ScannerActivity.java
private void navigateUp() {
    Intent intent = getParentActivityIntent();
    if (shouldUpRecreateTask(intent) || isTaskRoot()) {
        TaskStackBuilder.create(this).addNextIntentWithParentStack(intent).startActivities();
    } else {
        finish();
    }
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, TargetShortcutActivity.class))
            .setActivity(new ComponentName(context, EmptyActivity1.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(TargetShortcutActivity.class)
                    .addNextIntent(new Intent(context, TargetShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    disabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, DisabledShortcutActivity.class))
            .setDisabledMessage("DISABLED_MESSAGE")
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(DisabledShortcutActivity.class)
                    .addNextIntent(new Intent(context, DisabledShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, MethodShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(MethodShortcutActivity.class)
                    .addNextIntent(new Intent(context, MethodShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW)
                            .putExtra("shortbread_method", "shortcutMethod"))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(ShortcutUtils.getActivityLabel(context, SimpleShortcutActivity.class))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(SimpleShortcutActivity.class)
                    .addNextIntent(new Intent(context, SimpleShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
源代码23 项目: fitnotifications   文件: NLService.java
/**
 * Creates an intent to open Fit Notifications settings when notification is clicked.
 */
private PendingIntent createSettingsIntent() {
    // Creates an explicit intent for the SettingsActivity in the app
    Intent settingsIntent = new Intent(this, SettingsActivity.class);

    // The stack builder object will contain an artificial back stack for the started Activity.
    // This ensures that navigating backward from the Activity leads out of the application to
    // the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(SettingsActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(settingsIntent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
源代码24 项目: Walrus   文件: BulkReadCardsService.java
private Notification getNotification() {
    final NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if (notificationManager != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
            && notificationManager.getNotificationChannel(CHANNEL_ID) == null) {
        notificationManager.createNotificationChannel(
                new NotificationChannel(CHANNEL_ID,
                        getString(R.string.bulk_read_notification_channel_name),
                        NotificationManager.IMPORTANCE_LOW));
    }

    notificationBuilder
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getResources().getQuantityString(R.plurals.bulk_reading_from,
                    runners.size(), runners.size()))
            .setOngoing(true)
            .setProgress(0, 0, true)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setContentIntent(TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(new Intent(this, BulkReadCardsActivity.class))
                    .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setCategory(Notification.CATEGORY_SERVICE);
    }

    return notificationBuilder.build();
}
 
private Notification createStreamNotification(StreamInfo stream, @Nullable Bitmap image, boolean showViewers, Context context) {
    Intent resultIntent = LiveStreamActivity.createLiveStreamIntent(stream, false, context);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(MyStreamsActivity.class);
    stackBuilder.addNextIntent(resultIntent);

    PendingIntent clickIntent = stackBuilder.getPendingIntent(
            stream.getChannelInfo().getDisplayName().hashCode(),
            PendingIntent.FLAG_UPDATE_CURRENT
    );

    NotificationTextData textData = constructStreamNotificationText(stream, context);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, context.getString(R.string.live_streamer_notification_id))
            .setAutoCancel(false)
            .setContentTitle(textData.getTitle())
            .setContentText(textData.getContent())
            .setGroup(GROUP_KEY)
            .setWhen(stream.getStartedAt())
            .setShowWhen(true)
            .setSmallIcon(R.drawable.ic_notification_icon_refresh)
            .setColor(ContextCompat.getColor(context, R.color.primary))
            .setContentIntent(clickIntent)
            .setSound(null);

    if (image != null) {
        mBuilder.setLargeIcon(image);
    }

    if (showViewers) {
        mBuilder.setSubText(textData.getSubtext());
    }

    return mBuilder.build();
}
 
private void goToExperimentList() {
  if (getActivity() == null) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
      Log.d(TAG, "goToExperimentList called on null activity");
    }
    return;
  }

  if (claimExperimentsMode) {
    getActivity().finish();
    return;
  }

  Intent upIntent =
      getActivity() == null ? null : NavUtils.getParentActivityIntent(getActivity());
  if (upIntent == null) {
    // This is cheating a bit.  Currently, upIntent has only been observed to be null
    // when we're using panes mode, so here we just assume usePanes==true.
    Intent intent =
        MainActivity.launchIntent(getActivity(), R.id.navigation_item_experiments, true);
    getActivity().startActivity(intent);
    getActivity().finish();
    return;
  }
  if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent)
      || getArguments().getBoolean(ARG_CREATE_TASK, false)) {
    upIntent.putExtra(MainActivity.ARG_SELECTED_NAV_ITEM_ID, R.id.navigation_item_experiments);
    upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // TODO: Transition animation
    TaskStackBuilder.create(getActivity())
        .addNextIntentWithParentStack(upIntent)
        .startActivities();
  } else {
    NavUtils.navigateUpTo(getActivity(), upIntent);
  }
}
 
private void showWarningNotification() {
    //Set corresponding icon
    //if(Evidence.getMaxSeverity() > 2){
    //    mBuilder.setSmallIcon(R.mipmap.icon_warn_red);
    //    mBuilder.setLargeIcon(mWarnRed);
    //} else {
    //    mBuilder.setSmallIcon(R.mipmap.icon_warn_orange);
    //    mBuilder.setLargeIcon(mWarnOrange);
    //}
    //mBuilder.setContentText(mNotificationCount + " new warnings encountered.");

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.class);

    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(Const.LOG_TAG, 1, mBuilder.build());
}
 
源代码28 项目: thunderboard-android   文件: BleManager.java
private void sendNotification(Beacon beacon) {

        // check if notifications are enabled and allowed for the beacon
        if (!BleUtils.checkAllowNotifications(beacon.getBluetoothAddress(), preferenceManager.getPreferences())) {
            Timber.d("Notifications not allowed for : %s, address: %s", beacon.getBluetoothName(), beacon.getBluetoothAddress());
            return;
        }

        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(context)
                        .setContentTitle(context.getResources().getString(R.string.app_name))
                        .setContentText(String.format("%s is nearby.", beacon.getBluetoothName()))
                        .setSmallIcon(R.drawable.ic_stat_sl_beacon)
                        .setAutoCancel(true);


        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        Intent intent = new Intent(context, DemosSelectionActivity.class);
        intent.putExtra(ThunderBoardConstants.EXTRA_DEVICE_BEACON, (Parcelable) beacon);
        stackBuilder.addParentStack(DemosSelectionActivity.class);
        stackBuilder.addNextIntent(intent);

        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(resultPendingIntent);
        NotificationManager notificationManager =
                (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(beacon.getId3().toInt(), builder.build());
    }
 
源代码29 项目: RxGcm   文件: AppGcmReceiverUIBackground.java
private PendingIntent getPendingIntentForNotification(Application application, Message message) {
    Class<? extends Activity> classActivity =  message.target().equals(GcmServerService.TARGET_ISSUE_GCM) ? HostActivityIssues.class : HostActivitySupplies.class;

    Intent resultIntent = new Intent(application, classActivity);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(application);
    stackBuilder.addParentStack(classActivity);
    stackBuilder.addNextIntent(resultIntent);

    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
}
 
源代码30 项目: mConference-Framework   文件: BaseActivity.java
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();
    }
}
 
 类所在包
 同包方法