Example usage for android.app TaskStackBuilder create

List of usage examples for android.app TaskStackBuilder create

Introduction

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

Prototype

public static TaskStackBuilder create(Context context) 

Source Link

Document

Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.

Usage

From source file:org.tigase.messenger.phone.pro.service.XMPPService.java

private void processSubscriptionRequest(final SessionObject sessionObject, final Presence stanza,
        final BareJID jid) {
    Log.e(TAG, "Subscription request from  " + jid);

    retrieveVCard(sessionObject, jid);//from w  w w  . java 2s  .  c om

    String title = getString(R.string.notification_subscription_request_title, jid.toString());
    String text = getString(R.string.notification_subscription_request_text);

    Intent resultIntent = new Intent(this, SubscriptionRequestActivity.class);
    resultIntent.putExtra("account_name", sessionObject.getUserBareJid().toString());
    resultIntent.putExtra("jid", jid.toString());

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ChatActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent editServerSettingsPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            // .setSmallIcon(R.drawable.ic_messenger_icon)
            .setSmallIcon(R.drawable.ic_messenger_icon).setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setTicker(title).setContentTitle(title).setContentText(text)
            .setContentIntent(editServerSettingsPendingIntent)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);

    builder.setLights(0xff0000ff, 100, 100);

    // getNotificationManager().notify(notificationId, builder.build());

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(("request:" + sessionObject.getUserBareJid().toString() + ":" + jid).hashCode(),
            builder.build());
}

From source file:com.android.mms.transaction.MessagingNotification.java

private static void notifyFailed(Context context, boolean isDownload, long threadId, boolean noisy) {
    // TODO factor out common code for creating notifications
    boolean enabled = MessagingPreferenceActivity.getNotificationEnabled(context);
    if (!enabled) {
        return;/*  w  w  w .jav a 2 s  . c  o m*/
    }

    // Strategy:
    // a. If there is a single failure notification, tapping on the notification goes
    //    to the compose view.
    // b. If there are two failure it stays in the thread view. Selecting one undelivered
    //    thread will dismiss one undelivered notification but will still display the
    //    notification.If you select the 2nd undelivered one it will dismiss the notification.
    int totalFailedCount = getUndeliveredMessageCount(context);

    Intent failedIntent;
    Notification notification = new Notification();
    String title;
    String description;
    if (totalFailedCount > 1) {
        description = context.getString(R.string.notification_failed_multiple,
                Integer.toString(totalFailedCount));
        title = context.getString(R.string.notification_failed_multiple_title);
    } else {
        title = isDownload ? context.getString(R.string.message_download_failed_title)
                : context.getString(R.string.message_send_failed_title);

        description = context.getString(R.string.message_failed_body);
    }

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context);
    // Get failed intent by folder mode or conversation mode.
    if (MessageUtils.isMailboxMode()) {
        failedIntent = getFailedIntentFromFolderMode(context, totalFailedCount, isDownload);
        if (failedIntent == null) {
            return;
        } else if (isDownload) {
            // When isDownload is true, the valid threadId is passed into this function.
            failedIntent.putExtra(FAILED_DOWNLOAD_FLAG, true);
        } else {
            failedIntent.putExtra(UNDELIVERED_FLAG, true);
        }
    } else {
        failedIntent = getFailedIntentFromConversationMode(context, isDownload, threadId);
    }

    taskStackBuilder.addNextIntent(failedIntent);

    notification.icon = R.drawable.stat_notify_sms_failed;

    notification.tickerText = title;

    notification.setLatestEventInfo(context, title, description,
            taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT));

    if (noisy) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        boolean vibrate = sp.getBoolean(MessagingPreferenceActivity.NOTIFICATION_VIBRATE,
                false /* don't vibrate by default */);
        if (vibrate) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
        }

        String ringtoneStr = sp.getString(MessagingPreferenceActivity.NOTIFICATION_RINGTONE, null);
        notification.sound = TextUtils.isEmpty(ringtoneStr) ? null : Uri.parse(ringtoneStr);
    }

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

    if (isDownload) {
        notificationMgr.notify(DOWNLOAD_FAILED_NOTIFICATION_ID, notification);
    } else {
        notificationMgr.notify(MESSAGE_FAILED_NOTIFICATION_ID, notification);
    }
}

From source file:ua.mkh.weather.MainActivity.java

private void create_notif() {
    // TODO Auto-generated method stub
    // Prepare intent which is triggered if the
    // notification is selected
    String tittle = textView3.getText().toString();
    String subject = textView3.getText().toString();
    String body = "";
    /*//from w ww .  j a  v  a2 s  . c o m
    NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify=new Notification((Integer)img1.getTag(),tittle,System.currentTimeMillis());
    PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
            
    notify.setLatestEventInfo(getApplicationContext(),subject,body,pending);
    notif.notify(0, notify);
            
            
    final NotificationManager mgr=
    (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note=new Notification((Integer)img1.getTag(),
      "",
                                                System.currentTimeMillis());
                 
        // This pending intent will open after notification click
        PendingIntent i=PendingIntent.getActivity(this, 0,
                                        new Intent(),
                                        0);
                 
        note.setLatestEventInfo(this, tittle,
      "", i);
                 
        //After uncomment this line you will see number of notification arrived
        //note.number=2;
        mgr.notify(1, note);
                
                
        PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
        Resources r = getResources();
        Notification notification = new NotificationCompat.Builder(this)
        .setTicker("Tiket")
        .setSmallIcon(android.R.drawable.ic_menu_report_image)
        .setContentTitle("Title")
        .setContentText("Context Text")
        .setContentIntent(pi)
        .setAutoCancel(true)
        .build();
            
        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    */

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.widget);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews);
    // Creates an explicit intent for an Activity in your app  
    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);
    remoteViews.setOnClickPendingIntent(R.id.button1, resultPendingIntent);
    remoteViews.setTextViewText(R.id.textView1, nnn);
    remoteViews.setTextColor(R.id.textView1, getResources().getColor(R.color.white));
    remoteViews.setImageViewResource(R.id.imageView1, (Integer) img1.getTag());
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.  
    mNotificationManager.notify(100, mBuilder.build());

}

From source file:android.app.Activity.java

/**
 * This method is called whenever the user chooses to navigate Up within your application's
 * activity hierarchy from the action bar.
 *
 * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName}
 * was specified in the manifest for this activity or an activity-alias to it,
 * default Up navigation will be handled automatically. If any activity
 * along the parent chain requires extra Intent arguments, the Activity subclass
 * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}
 * to supply those arguments.</p>//ww w  .j  a v a  2s  .com
 *
 * <p>See <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back Stack</a>
 * from the developer guide and <a href="{@docRoot}design/patterns/navigation.html">Navigation</a>
 * from the design guide for more information about navigating within your app.</p>
 *
 * <p>See the {@link TaskStackBuilder} class and the Activity methods
 * {@link #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and
 * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation.
 * The AppNavigation sample application in the Android SDK is also available for reference.</p>
 *
 * @return true if Up navigation completed successfully and this Activity was finished,
 *         false otherwise.
 */
public boolean onNavigateUp() {
    // Automatically handle hierarchical Up navigation if the proper
    // metadata is available.
    Intent upIntent = getParentActivityIntent();
    if (upIntent != null) {
        if (mActivityInfo.taskAffinity == null) {
            // Activities with a null affinity are special; they really shouldn't
            // specify a parent activity intent in the first place. Just finish
            // the current activity and call it a day.
            finish();
        } else if (shouldUpRecreateTask(upIntent)) {
            TaskStackBuilder b = TaskStackBuilder.create(this);
            onCreateNavigateUpTaskStack(b);
            onPrepareNavigateUpTaskStack(b);
            b.startActivities();

            // We can't finishAffinity if we have a result.
            // Fall back and simply finish the current activity instead.
            if (mResultCode != RESULT_CANCELED || mResultData != null) {
                // Tell the developer what's going on to avoid hair-pulling.
                Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result");
                finish();
            } else {
                finishAffinity();
            }
        } else {
            navigateUpTo(upIntent);
        }
        return true;
    }
    return false;
}