下面列出了怎么用android.support.v4.app.TaskStackBuilder的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testDeepLinkIntent() {
NavController navController = createNavController();
navController.setGraph(R.navigation.nav_simple);
Bundle args = new Bundle();
args.putString("test", "test");
TaskStackBuilder taskStackBuilder = navController.createDeepLink()
.setDestination(R.id.second_test)
.setArguments(args)
.createTaskStackBuilder();
Intent intent = taskStackBuilder.editIntentAt(0);
assertThat(intent, is(notNullValue()));
navController.onHandleDeepLink(intent);
// The original Intent should be untouched and safely writable to a Parcel
Parcel p = Parcel.obtain();
intent.writeToParcel(p, 0);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = Intent.makeMainActivity(new ComponentName(this, MainActivity.class));
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.create(this)
.addNextIntent(upIntent).startActivities();
finish();
} else {
// This activity is part of the application's task, so simply
// navigate up to the hierarchical parent activity.
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(upIntent);
finish();
}
return true;
}
return super.onOptionsItemSelected(item);
}
@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);
NavUtils.navigateUpTo(this, upIntent);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/** Starts the Settings Activity if connection settings are missing
*
* @return true if setup was started
*/
private boolean startSetupIfNeeded(){
Preferences preferences = new Preferences(getApplicationContext());
if (TextUtils.isEmpty(preferences.getString(R.string.pref_key_host, null)) || preferences.getInt(R.string.pref_key_port, -1) == -1){
Intent settingsIntent = new Intent(this, SettingsActivity.class);
settingsIntent.putExtra(SettingsActivity.EXTRA_SHOW_TOAST_KEY, SettingsActivity.EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE);
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Use TaskStackBuilder to make sure the MainActivity opens when the SettingsActivity is closed
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(settingsIntent)
.startActivities();
Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(closeIntent);
return true;
}
return false;
}
public static void showNotification(Context context,Class<?> cls,String title,String content)
{
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Intent notificationIntent = new Intent(context, cls);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(DAILY_REMINDER_REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context,context.getPackageName());
Notification notification = builder.setContentTitle(title)
.setContentText(content)
.setAutoCancel(true)
.setSound(alarmSound)
.setSmallIcon(R.drawable.app_icon_144)
.setContentIntent(pendingIntent).build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(DAILY_REMINDER_REQUEST_CODE, notification);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (upIntent == null) {
finish();
} else {
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
}
return true;
}
return super.onOptionsItemSelected(item);
}
@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);
NavUtils.navigateUpTo(this, upIntent);
}
return true;
case R.id.action_open_link:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(article.getPermaLink());
intent.addCategory(Intent.CATEGORY_BROWSABLE);
this.startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
// This activity is NOT part of this app's task, so create a new task
// when navigating up, with a synthesized back stack.
TaskStackBuilder.create(this)
// Add all of this activity's parents to the back stack
.addNextIntentWithParentStack(upIntent)
// Navigate up to the closest parent
.startActivities();
} else {
// This activity is part of this app's task, so simply
// navigate up to the logical parent activity.
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
public void myStartForeground() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("计步器")
.setContentText("正在运行");
Intent notificationIntent = new Intent(this, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(notificationIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
startForeground(1, mBuilder.build());
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home://返回上一菜单页
AppToast.getToast().show("返回上一页");
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.create(this).addNextIntentWithParentStack(upIntent).startActivities();
} else {
upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
NavUtils.navigateUpTo(this, upIntent);
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
/**
* Surface a notification to the user that the Physical Web is broadcasting. The notification
* specifies the transport or URL that is being broadcast and cannot be swiped away.
* @param context
* @param stopServiceReceiver
* @param broadcastNotificationId
* @param title
* @param text
* @param filter
*/
public static void createBroadcastNotification(Context context,
BroadcastReceiver stopServiceReceiver, int broadcastNotificationId, CharSequence title,
CharSequence text, String filter) {
Intent resultIntent = new Intent();
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
context.registerReceiver(stopServiceReceiver, new IntentFilter(filter));
PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, new Intent(filter),
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_leak_add_white_24dp)
.setContentTitle(title)
.setContentText(text)
.setOngoing(true)
.addAction(android.R.drawable.ic_menu_close_clear_cancel,
context.getString(R.string.stop), pIntent);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
notificationManager.notify(broadcastNotificationId, builder.build());
}
@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);
NavUtils.navigateUpTo(this, upIntent);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_add_repo:
showAddRepo();
return true;
case android.R.id.home:
Intent upIntent = NavUtils.getParentActivityIntent(this);
if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@NonNull
private TaskStackBuilder stackBuilderForNotificationTap(Message message) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
Bundle messageBundle = MessageBundleMapper.messageToBundle(message);
Class[] classes = propertyHelper().findClasses(MobileMessagingChatProperty.ON_MESSAGE_TAP_ACTIVITY_CLASSES);
if (classes != null) {
for (Class cls : classes) {
stackBuilder.addNextIntent(new Intent(context, cls)
.setAction(Event.NOTIFICATION_TAPPED.getKey())
.putExtras(messageBundle));
}
}
NotificationSettings notificationSettings = MobileMessagingCore.getInstance(context).getNotificationSettings();
if (stackBuilder.getIntentCount() == 0 && notificationSettings != null && notificationSettings.getCallbackActivity() != null) {
stackBuilder.addNextIntent(new Intent(context, notificationSettings.getCallbackActivity())
.setAction(Event.NOTIFICATION_TAPPED.getKey())
.putExtras(messageBundle));
}
return stackBuilder;
}
@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);
NavUtils.navigateUpTo(this, upIntent);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void sendNotificationShareError(Link link) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Failed to share " + link.getTitle())
.setContentText("Press to try again")
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_LOW);
// Creates an explicit intent To relaunch this service
Intent resultIntent = new Intent(this, NetworkService.class);
resultIntent.putExtra("action", NetworkService.INTENT_POST);
resultIntent.putExtra("link", link);
resultIntent.putExtra(Intent.EXTRA_TEXT, link.getUrl());
resultIntent.putExtra(Intent.EXTRA_SUBJECT, link.getTitle());
// 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 Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = PendingIntent.getService(this, 0, resultIntent, 0);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(link.getUrl().hashCode(), mBuilder.build());
}
/**
* 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();
}
}
@Test
public void testDeepLinkFromNavGraph() {
NavController navController = createNavController();
navController.setGraph(R.navigation.nav_simple);
TaskStackBuilder taskStackBuilder = navController.createDeepLink()
.setDestination(R.id.second_test)
.createTaskStackBuilder();
assertThat(taskStackBuilder, is(notNullValue(TaskStackBuilder.class)));
assertThat(taskStackBuilder.getIntentCount(), is(1));
}
/**
* 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();
}
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
boolean isFirst=SPUtils.getInstance().getBoolean(AppConstant.IS_FIRST_ENTER,true);
if(isFirst){
TaskStackBuilder.create(SplashActivity.this)
.addNextIntentWithParentStack(new Intent(SplashActivity.this, MainActivity.class))
.addNextIntent(new Intent(SplashActivity.this, IntroActivity.class))
.startActivities();
finish();
}else{
startActivity(MainActivity.class);
finish();
}
}
/**
* @param context Application context.
* @return Pending Intent for competition.
*/
private static PendingIntent getCompetitionWinnersListPendingIntent(Context context, String compId, String compTitle) {
Intent intent = new Intent(context, WinnersFeedListActivity.class);
Bundle bundle = new Bundle();
intent.putExtras(bundle);
intent.putExtra(EXTRA_COMPETITION_ID, compId);
intent.putExtra(EXTRA_COMPETITION_TITLE, compTitle);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntentWithParentStack(intent);
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
/**
* @param context Application context.
* @return Pending Intent for competition.
*/
public static PendingIntent getCompetitionListingPendingIntent(Context context) {
Intent intent = new Intent(context, HomeActivity.class);
Bundle bundle = new Bundle();
intent.putExtras(bundle);
intent.putExtra(EXTRA_TAB_INDEX, 1);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntentWithParentStack(intent);
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
public static Notification buildCallNotification(Context context, String roomName, String roomId, String matrixId, String callId) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setWhen(System.currentTimeMillis());
builder.setContentTitle(roomName);
builder.setContentText(context.getString(R.string.call_in_progress));
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
builder.setSmallIcon(R.drawable.ic_menu_small_matrix);
} else {
builder.setSmallIcon(R.drawable.ic_menu_small_matrix_transparent);
}
// Build the pending intent for when the notification is clicked
Intent roomIntent = new Intent(context, RoomActivity.class);
roomIntent.putExtra(RoomActivity.EXTRA_ROOM_ID, roomId);
roomIntent.putExtra(RoomActivity.EXTRA_MATRIX_ID, matrixId);
roomIntent.putExtra(RoomActivity.EXTRA_START_CALL_ID, callId);
// Recreate the back stack
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context)
.addParentStack(RoomActivity.class)
.addNextIntent(roomIntent);
// android 4.3 issue
// use a generator for the private requestCode.
// When using 0, the intent is not created/launched when the user taps on the notification.
//
PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000), PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
Notification n = builder.build();
n.flags |= Notification.FLAG_SHOW_LIGHTS;
n.defaults |= Notification.DEFAULT_LIGHTS;
return n;
}
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();
}
}
public static void show(Context context, RemoteViews normal, RemoteViews expanded) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, PlaybackActivity.class);
// The stack builder 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(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(PlaybackActivity.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);
builder.setContentIntent(resultPendingIntent);
boolean isTransparent = Preferences.get(context).isNotificationIconTransparent();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification n = builder.setContent(normal)
.setWhen(0)
.setOngoing(true)
.setSmallIcon(isTransparent ? R.drawable.ic_transparent : R.drawable.ic_vlc_server)
.build();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
n.bigContentView = expanded;
}
notificationManager.notify(ID, n);
}
private void bootCheckForAppUpdate() {
log("Checking for app update...");
UpdateChecker.checkForUpdate(new UpdateChecker.Callback() {
@Override
public void onSuccess(final UpdateChecker.AppUpdateData appUpdateData) {
log("update check onSuccess");
if (UpdateChecker.isOldVersion(appUpdateData)) {
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mUpdate = new NotificationCompat.Builder(BootService.this);
mUpdate.setContentTitle(getString(R.string.update_available))
.setContentText(getString(R.string.update_available_open_app))
.setSmallIcon(R.drawable.ic_launcher_preview);
TaskStackBuilder updatestackBuilder = TaskStackBuilder.create(BootService.this);
updatestackBuilder.addParentStack(MainActivity.class);
updatestackBuilder.addNextIntent(new Intent(BootService.this, MainActivity.class));
PendingIntent updatependingIntent = updatestackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mUpdate.setContentIntent(updatependingIntent);
mNotifyManager.notify(id, mUpdate.build());
}
}
@Override
public void onError() {
log("update check onSuccess");
}
} , getString(R.string.APP_UPDATE_URL));
}
/**
* 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();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
/* This is called when the Home (Up) button is pressed
* in the Action Bar. http://goo.gl/lJxjA */
Intent upIntent = new Intent(this, MainActivity.class);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.from(this)
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
case R.id.menu_preferences:
Intent preferencesActivity = new Intent(getBaseContext(),
SettingsActivity.class);
startActivity(preferencesActivity);
return true;
case R.id.menu_upload:
if (Constants.PRO_VERSION) {
Intent localPhotosActivity = new Intent(getBaseContext(),
LocalPhotosActivity.class);
startActivity(localPhotosActivity);
} else {
BuyProDialog.show(this);
}
return true;
case R.id.menu_about:
new AboutDialogFragment().show(getSupportFragmentManager(), "AboutDialogFragment");
return true;
}
return super.onOptionsItemSelected(item);
}
public void createNotification(String text, Context context) {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Test notification")
.setContentText(text);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, MainNormalActivity.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(context);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainNormalActivity.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(676, mBuilder.build());
}