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:capstone.se491_phm.gcm.PhmGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from  ww w.  jav  a 2 s .  c  o  m*/
 */
private void sendNotification(String message) {
    Context context = getBaseContext();
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(Constants.SERVER_IP, message);
    editor.commit();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.notification).setContentTitle("External Sensor Request")
            .setContentText("A connection request has been made from this ip: " + message
                    + ". Click to allow connection")
            .setSound(defaultSoundUri);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, ExternalSensorActivity.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(ExternalSensorActivity.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);
    // mId allows you to update the notification later on.
    MainActivity.mNotificationManager.notify(notificationId, mBuilder.build());
}

From source file:com.conceptberria.wattion.background.MakeNotification.java

/**
 * Para versiones mas alta que JellyBean genera un intent aadiendo en la pila de tareas la actividad {@link ViewPrice}
 * @return el intent/*from   ww w .jav  a  2s. c  o m*/
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private PendingIntent getPendingIntentWithStackBuilder() {
    Intent resultIntent = new Intent(this, ViewPrice.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(ViewPrice.class);
    stackBuilder.addNextIntent(resultIntent);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}

From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *//*from   w  w w .ja  v  a  2 s  .  c om*/
private void sendNotification(String nameofsensor) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.drawable.icon)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED)
            .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor)
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.ibm.mf.geofence.demo.MyGeofenceReceiver.java

private void sendNotification(Context context, List<MFGeofence> fences, String type) {
    String title = "Geofence: " + type;
    StringBuilder sb = new StringBuilder();
    int count = 0;
    for (MFGeofence g : fences) {
        if (count > 0)
            sb.append('\n');
        sb.append(String.format("%s : lat=%.6f; lng=%.6f; radius=%.0f m", g.getName(), g.getLatitude(),
                g.getLongitude(), g.getRadius()));
        count++;/*w w w. j av  a 2  s .c o  m*/
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setAutoCancel(true)
            .setSmallIcon(android.R.drawable.ic_notification_overlay).setContentTitle(title)
            .setContentText(sb.toString());
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MapsActivity.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(MapsActivity.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) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(notifId.incrementAndGet(), mBuilder.build());
}

From source file:com.mienaikoe.deltamonitor.CameraWatcherService.java

private void notifyMessage(String title, String message) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setContentTitle(title).setContentText(message);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MotionDetectionActivity.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);
    stackBuilder.addParentStack(MotionDetectionActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    if (notifier == null) {
        notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }// www .j  av a2  s .co m
    notifier.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:org.catnut.service.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/* w  ww .  j  a  v  a  2  s  . c  o m*/
    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());
}

From source file:com.hkm.taxicallandroid.schema.ConfirmCall.java

private void generate_notification(final CallPanel ctx) {

    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_talkrequirements).setContentTitle("Incoming Taxi").setContentText(String
                    .format(content_f, incoming_driver_data.getLicense(), incoming_driver_data.getEstTime()));
    // Creates an explicit intent for an Activity in your app
    final Intent resultIntent = new Intent(ctx, CallPanel.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(CallPanel.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(39939, mBuilder.build());

}

From source file:com.example.maciej.mytask.MainActivity.java

public void createNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.add)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.notification_desc));
    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(12, mBuilder.build());
}

From source file:com.i2r.alan.rate_this_place.visitedplace.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *//*from w  w  w  .  jav  a 2 s .  c  o  m*/
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), VisitedPlacesActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(com.i2r.alan.rate_this_place.R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),
                    com.i2r.alan.rate_this_place.R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails)
            .setContentText(
                    getString(com.i2r.alan.rate_this_place.R.string.geofence_transition_notification_text))
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.fairphone.updater.UpdaterService.java

private void setNotification() {

    Context context = getApplicationContext();

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.fairphone_updater_tray_icon_small)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.fairphone_updater_tray_icon))
            .setContentTitle(context.getResources().getString(R.string.app_name))
            .setContentText(getResources().getString(R.string.fairphoneUpdateMessage));

    Intent resultIntent = new Intent(context, FairphoneUpdater.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

    stackBuilder.addParentStack(FairphoneUpdater.class);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(resultPendingIntent);

    Notification notificationWhileRunnig = builder.build();

    // Add notification
    manager.notify(0, notificationWhileRunnig);

}