Example usage for android.app TaskStackBuilder addNextIntentWithParentStack

List of usage examples for android.app TaskStackBuilder addNextIntentWithParentStack

Introduction

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

Prototype

public TaskStackBuilder addNextIntentWithParentStack(Intent nextIntent) 

Source Link

Document

Add a new Intent with the resolved chain of parents for the target activity to the task stack.

Usage

From source file:net.wespot.pim.view.InqCommunicateFragment.java

private void createNotification(MessageLocalObject messageLocalObject, Long runId) {

    if (!runIdList.contains(runId)) {
        runIdList.add(runId);//from   www. j  a va2  s .com
        runIdList_str.add(runId.toString());
    }

    numMessages = 0;
    mBuilder = null;
    mNotificationStyle = null;
    mNotificationManager = null;

    mNotificationManager = (NotificationManager) ARL.getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationStyle = new NotificationCompat.InboxStyle();
    mBuilder = new NotificationCompat.Builder(ARL.getContext()).setSmallIcon(R.drawable.ic_launcher)
            .setAutoCancel(true).setSortKey("0")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setStyle(mNotificationStyle);

    InquiryLocalObject inquiryLocalObject = DaoConfiguration.getInstance().getInquiryLocalObjectDao()
            .queryBuilder().where(InquiryLocalObjectDao.Properties.RunId.eq(runId)).list().get(0);

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

    Intent resultIntent;

    if (runIdList.size() > 1) {
        resultIntent = new Intent(ARL.getContext(), PimInquiriesFragment.class);
        resultIntent.putStringArrayListExtra(INQUIRIES_ID, (ArrayList<String>) runIdList_str);

        Intent parent = new Intent(ARL.getContext(), MainActivity.class);
        Intent parent1 = new Intent(ARL.getContext(), SplashActivity.class);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addNextIntentWithParentStack(parent1);
        stackBuilder.addNextIntentWithParentStack(parent);

    } else {
        resultIntent = new Intent(ARL.getContext(), InquiryPhasesActivity.class);
        resultIntent.putExtra(INQUIRY_ID, inquiryLocalObject.getId());

        Intent parent = new Intent(ARL.getContext(), PimInquiriesFragment.class);
        Intent parent1 = new Intent(ARL.getContext(), MainActivity.class);
        Intent parent2 = new Intent(ARL.getContext(), SplashActivity.class);

        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addNextIntentWithParentStack(parent2);
        stackBuilder.addNextIntentWithParentStack(parent1);
        stackBuilder.addNextIntentWithParentStack(parent);
    }

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

    if (runIdList.size() == 1) {
        // More than 1 inquiries have messages

        mBuilder.setContentTitle(inquiryLocalObject.getTitle());
        for (MessageLocalObject me : notications_queue_messages) {
            mNotificationStyle.addLine(getNameUser(me.getAuthor()) + ": " + me.getBody()).setSummaryText(
                    ++numMessages != 1 ? numMessages + " new messages" : numMessages + " new message");
        }
    }

    if (runIdList.size() > 1) {
        // More than 1 inquiries have messages

        for (MessageLocalObject me : notications_queue_messages) {
            mBuilder.setContentTitle("Personal Inquiry Manager");
            InquiryLocalObject a = DaoConfiguration.getInstance().getInquiryLocalObjectDao().queryBuilder()
                    .where(InquiryLocalObjectDao.Properties.RunId.eq(me.getRunId())).list().get(0);

            mNotificationStyle.addLine(getNameUser(me.getAuthor()) + " @ " + a.getTitle() + ": " + me.getBody())
                    .setSummaryText(++numMessages != 1
                            ? numMessages + " new messages from " + runIdList.size() + " conversations" + " "
                            : numMessages + " new message from " + runIdList.size() + " conversations");
        }
    }

    mNotificationManager.notify(Integer.parseInt(NUMBER), mBuilder.build());
}