# ActivityBackStackTest **Repository Path**: threekiloton/ActivityBackStackTest ## Basic Information - **Project Name**: ActivityBackStackTest - **Description**: activity 回退栈测试 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-09-28 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Activity构建导航 * 添加parent ``` ``` * 构建任务栈 ``` Intent intent = new Intent( this, DetailActivity.class ); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP ); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create( this ); taskStackBuilder.addParentStack( DetailActivity.class ); taskStackBuilder.addNextIntent( intent ); ``` * 可以直接启动 ``` taskStackBuilder.startActivities(); ``` ![](img/pic01.gif) * 可是使用Notification ``` PendingIntent pendingIntent = taskStackBuilder .getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); String channel = getChannel(); Notification notification = new Builder( this, channel ) .setSmallIcon( R.drawable.ic_launcher_foreground ) .setContentTitle( "new Notification" ) .setContentText( "this is a TaskStack notification " ) .setAutoCancel( true ) .setContentIntent( pendingIntent ) .build(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE ); assert notificationManager != null; notificationManager.notify( 12, notification ); ``` ``` private String getChannel ( ) { if( VERSION.SDK_INT > VERSION_CODES.O ) { int importance = NotificationManager.IMPORTANCE_DEFAULT; /* 必须设置 importance */ NotificationChannel channel = new NotificationChannel( "CHANNEL", "CHANNEL_NAME", importance ); channel.setDescription( "this is test notification channel" ); NotificationManager notificationManager = getSystemService( NotificationManager.class ); assert notificationManager != null; notificationManager.createNotificationChannel( channel ); return "CHANNEL"; } else { return "CHANNEL"; } } ``` ![](img/pic02.gif)