Example usage for android.app TaskStackBuilder addParentStack

List of usage examples for android.app TaskStackBuilder addParentStack

Introduction

In this page you can find the example usage for android.app TaskStackBuilder addParentStack.

Prototype

public TaskStackBuilder addParentStack(ComponentName sourceActivityName) 

Source Link

Document

Add the activity parent chain as specified by the android.R.attr#parentActivityName parentActivityName attribute of the activity (or activity-alias) element in the application's manifest to the task stack builder.

Usage

From source file:io.northernlights.logcleaner.Notifier.java

public static void showNotification(String title, String text, Context context) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(text);

    Intent resultIntent = new Intent(context, MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    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);

    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:com.breadwallet.tools.manager.BRNotificationManager.java

public static void sendNotification(Activity ctx, int icon, String title, String message, int mId) {
    if (ctx == null)
        return;//ww w  .j ava 2  s .  c o m
    android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, 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(ctx);
    // 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) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}

From source file:io.digibyte.tools.manager.BRNotificationManager.java

public static void sendNotification(Context ctx, int icon, String title, String message, int mId) {
    if (ctx == null)
        return;// w ww  .j  av  a  2  s .c o m
    android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(icon).setContentTitle(title).setContentText(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(ctx, BreadActivity.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(ctx);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(BreadActivity.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) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(mId, mBuilder.build());
}

From source file:com.codemobiles.util.CMNotification.java

public static Notification setNormalNotification(Context ctx, int iconResID, Bitmap remote_picture,
        String title, String desc, Class<?> receiver) {

    // Setup an explicit intent for an SuccessActivity to receive.
    Intent resultIntent = new Intent(ctx, receiver);

    // TaskStackBuilder ensures that the back button follows the recommended
    // convention for the back key.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx);

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

    // 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);

    return new NotificationCompat.Builder(ctx).setSmallIcon(iconResID).setAutoCancel(true)
            .setLargeIcon(remote_picture).setContentIntent(resultPendingIntent).setContentTitle(title)
            .setContentText(desc).build();
}

From source file:hmatalonga.greenhub.util.Notifier.java

public static void startStatusBar(final Context context) {
    if (isStatusBarShown)
        return;/*from ww w  .ja v  a  2s .co  m*/

    // At this moment Inspector still doesn't have a current level assigned
    DataEstimator estimator = new DataEstimator();
    estimator.getCurrentStatus(context);

    int now = Battery.getBatteryCurrentNow(context);
    int level = estimator.getLevel();
    String title = "Now: " + now + " mA";
    String text = "GreenHub is running";

    sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text)
            .setAutoCancel(false).setOngoing(true)
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    if (level < 100) {
        sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level);
    } else {
        sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, 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(context);
    // 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);
    sBuilder.setContentIntent(resultPendingIntent);
    sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build());
    isStatusBarShown = true;
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void batteryFullAlert(final Context context) {
    if (sNotificationManager == null) {
        sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }/*from  w  ww.j  av a 2s  .c  o m*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_information_white_24dp)
            .setContentTitle(context.getString(R.string.notif_battery_full))
            .setContentText(context.getString(R.string.notif_remove_charger)).setAutoCancel(true)
            .setOngoing(false).setLights(Color.GREEN, 500, 2000).setVibrate(new long[] { 0, 400, 1000 })
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, 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(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(InboxActivity.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);

    // Because the ID remains unchanged, the existing notification is updated.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_FULL, mBuilder.build());
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void batteryLowAlert(final Context context) {
    if (sNotificationManager == null) {
        sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }//from   ww  w  .  ja va  2 s.com

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_alert_circle_white_24dp)
            .setContentTitle(context.getString(R.string.notif_battery_low))
            .setContentText(context.getString(R.string.notif_connect_power)).setAutoCancel(true)
            .setOngoing(false).setLights(Color.RED, 500, 2000).setVibrate(new long[] { 0, 400, 1000 })
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, 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(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(InboxActivity.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);

    // Because the ID remains unchanged, the existing notification is updated.
    sNotificationManager.notify(Config.NOTIFICATION_BATTERY_LOW, mBuilder.build());
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void newMessageAlert(final Context context) {
    if (sNotificationManager == null) {
        sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }//from   ww  w . j av  a  2s  .  co m

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_email_white_24dp)
            .setContentTitle(context.getString(R.string.notif_new_message))
            .setContentText(context.getString(R.string.notif_open_inbox)).setAutoCancel(true).setOngoing(false)
            .setLights(Color.GREEN, 500, 2000).setVibrate(new long[] { 0, 800, 1500 })
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, InboxActivity.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(InboxActivity.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);

    // Because the ID remains unchanged, the existing notification is updated.
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    sNotificationManager.notify(Config.NOTIFICATION_MESSAGE_NEW, notification);
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void batteryWarningTemperature(final Context context) {
    if (sNotificationManager == null) {
        sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }//from w w w .j ava 2  s . c  om

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_alert_circle_white_24dp)
            .setContentTitle(context.getString(R.string.notif_battery_warning))
            .setContentText(context.getString(R.string.notif_battery_warm)).setAutoCancel(true)
            .setOngoing(false).setLights(Color.YELLOW, 500, 2000).setVibrate(new long[] { 0, 400, 1000 })
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.putExtra("tab", 2);

    // 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(InboxActivity.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);

    // Because the ID remains unchanged, the existing notification is updated.
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_WARNING, notification);
}

From source file:com.hmatalonga.greenhub.util.Notifier.java

public static void batteryHighTemperature(final Context context) {
    if (sNotificationManager == null) {
        sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }// w ww. j  ava 2 s  . co m

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_alert_circle_white_24dp)
            .setContentTitle(context.getString(R.string.notif_battery_hot))
            .setContentText(context.getString(R.string.notif_battery_cooldown)).setAutoCancel(true)
            .setOngoing(false).setLights(Color.RED, 500, 2000).setVibrate(new long[] { 0, 800, 1500 })
            .setPriority(SettingsUtils.fetchNotificationsPriority(context));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);
    resultIntent.putExtra("tab", 2);

    // 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(InboxActivity.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);

    // Because the ID remains unchanged, the existing notification is updated.
    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_HIGH, notification);
}