Java Code Examples for android.support.v4.app.TaskStackBuilder

The following are top voted examples for showing how to use android.support.v4.app.TaskStackBuilder. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: FeedActivity.java   View source code 7 votes vote down vote up
@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);
}
 
Example 2
Project: android-mvp-interactor-architecture   File: FeedActivity.java   View source code 7 votes vote down vote up
@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);
}
 
Example 3
Project: iosched-reader   File: TaskStackBuilderProxyActivity.java   View source code 7 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    Intent proxyIntent = getIntent();
    if (!proxyIntent.hasExtra(EXTRA_INTENTS)) {
        finish();
        return;
    }

    for (Parcelable parcelable : proxyIntent.getParcelableArrayExtra(EXTRA_INTENTS)) {
        builder.addNextIntent((Intent) parcelable);
    }

    builder.startActivities();
    finish();
}
 
Example 4
Project: q-mail   File: NotificationActionCreator.java   View source code 6 votes vote down vote up
public PendingIntent createViewMessagesPendingIntent(Account account, List<MessageReference> messageReferences,
        int notificationId) {

    TaskStackBuilder stack;
    if (account.goToUnreadMessageSearch()) {
        stack = buildUnreadBackStack(account);
    } else {
        String folderId = getFolderIdOfAllMessages(messageReferences);

        if (folderId == null) {
            stack = buildFolderListBackStack(account);
        } else {
            stack = buildMessageListBackStack(account, folderId);
        }
    }

    return stack.getPendingIntent(notificationId, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
}
 
Example 5
Project: jazz-android   File: MainActivity.java   View source code 6 votes vote down vote up
private void sendNotification(String author, String value) {
    // The id of the channel.
    String CHANNEL_ID = "jazz_01";
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this, CHANNEL_ID)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setAutoCancel(true)
                    .setContentTitle(author)
                    .setContentText(value);
    // 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 app 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
            );
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    // mNotificationId is a unique integer your app uses to identify the
    // notification. For example, to cancel the notification, you can pass its ID
    // number to NotificationManager.cancel().
    mNotificationManager.notify(1, mBuilder.build());
}
 
Example 6
Project: hypertrack-live-android   File: Profile.java   View source code 6 votes vote down vote up
private void startPlacelineScreen() {
    CrashlyticsWrapper.setCrashlyticsKeys(this);
    showProgress(false);

    // Clear Existing running trip on Registration Successful
    SharedPreferenceManager.deleteAction(this);
    SharedPreferenceManager.deletePlace(this);

    HyperLog.i(TAG, "User Registration successful: Clearing Active Trip, if any");
    Intent intent = new Intent(Profile.this, Placeline.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    TaskStackBuilder.create(Profile.this)
            .addNextIntentWithParentStack(intent)
            .startActivities();
    finish();
}
 
Example 7
Project: hypertrack-live-android   File: Verify.java   View source code 6 votes vote down vote up
private void startPlacelineScreen() {
    CrashlyticsWrapper.setCrashlyticsKeys(this);
    showProgress(false);

    // Clear Existing running trip on Registration Successful
    SharedPreferenceManager.deleteAction(this);
    SharedPreferenceManager.deletePlace(this);

    HyperLog.i(TAG, "User Registration successful: Clearing Active Trip, if any");
    Intent intent = new Intent(Verify.this, Placeline.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    TaskStackBuilder.create(Verify.this)
            .addNextIntentWithParentStack(intent)
            .startActivities();
    finish();
}
 
Example 8
Project: hypertrack-live-android   File: SplashScreen.java   View source code 6 votes vote down vote up
private void handleTrackingDeepLinkError() {
    ActionManager actionManager = ActionManager.getSharedManager(this);
    //Check if there is any existing task to be restored
    if (actionManager.shouldRestoreState()) {
        TaskStackBuilder.create(this)
                .addNextIntentWithParentStack(new Intent(this, Home.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .startActivities();
    } else {
        TaskStackBuilder.create(this)
                .addNextIntentWithParentStack(new Intent(this, Placeline.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .startActivities();
    }
    finish();
    actionManager = null;
}
 
Example 9
Project: OTAUpdates   File: MainActivity.java   View source code 6 votes vote down vote up
private void create_notification(int id, String title, String content) {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(
                    (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
                            ? R.drawable.app_icon_notification : R.drawable.app_icon))
            .setContentTitle(title)
            .setContentText(content);

    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(id, mBuilder.build());
}
 
Example 10
Project: orgzly-android   File: ShareActivity.java   View source code 6 votes vote down vote up
public static PendingIntent createNewNoteIntent(Context context, Filter filter) {
        Intent resultIntent = new Intent(context, ShareActivity.class);
        resultIntent.setAction(Intent.ACTION_SEND);
        resultIntent.setType("text/plain");
        resultIntent.putExtra(Intent.EXTRA_TEXT, "");

        if (filter != null && filter.getQuery() != null) {
            resultIntent.putExtra(AppIntent.EXTRA_FILTER, filter.getQuery());
        }

        // 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(ShareActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);

//        return PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    }
 
Example 11
Project: proto-collecte   File: StopCollecteActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    if (sharedPref.getBoolean(SettingsActivity.KEY_COLLECTE_ACTIVER, false)) {
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean(SettingsActivity.KEY_COLLECTE_ACTIVER, false);
        editor.commit();
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(new Intent(this, MainActivity.class));
    stackBuilder.addParentStack(MainActivity.class);

    stackBuilder.startActivities();
}
 
Example 12
Project: service-visit-example-android   File: SplashScreen.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Check if Driver is logged in currently
    String driverId = SharedPreferenceStore.getDriverId(this);
    if (TextUtils.isEmpty(driverId)) {

        // Initiate Driver Login by starting LoginActivity
        TaskStackBuilder.create(SplashScreen.this)
                .addNextIntentWithParentStack(new Intent(SplashScreen.this, LoginActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .startActivities();
        finish();
    } else {

        // Start Driver Session by starting MainActivity
        TaskStackBuilder.create(SplashScreen.this)
                .addNextIntentWithParentStack(new Intent(SplashScreen.this, MainActivity.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
                .startActivities();
        finish();
    }
}
 
Example 13
Project: iosched-reader   File: BaseActivity.java   View source code 6 votes vote down vote up
/**
 * This utility method handles Up navigation intents by searching for a parent activity and
 * navigating there if defined. When using this for an activity make sure to define both the
 * native parentActivity as well as the AppCompat one when supporting API levels less than 16.
 * when the activity has a single parent activity. If the activity doesn't have a single parent
 * activity then don't define one and this method will use back button functionality. If "Up"
 * functionality is still desired for activities without parents then use
 * {@code syntheticParentActivity} to define one dynamically.
 *
 * Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
 *       in Material Design guidelines.
 *
 * @param currentActivity Activity in use when navigate Up action occurred.
 * @param syntheticParentActivity Parent activity to use when one is not already configured.
 */
public static void navigateUpOrBack(Activity currentActivity,
                                    Class<? extends Activity> syntheticParentActivity) {
    // Retrieve parent activity from AndroidManifest.
    Intent intent = NavUtils.getParentActivityIntent(currentActivity);

    // Synthesize the parent activity when a natural one doesn't exist.
    if (intent == null && syntheticParentActivity != null) {
        try {
            intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (intent == null) {
        // No parent defined in manifest. This indicates the activity may be used by
        // in multiple flows throughout the app and doesn't have a strict parent. In
        // this case the navigation up button should act in the same manner as the
        // back button. This will result in users being forwarded back to other
        // applications if currentActivity was invoked from another application.
        currentActivity.onBackPressed();
    } else {
        if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
            // Need to synthesize a backstack since currentActivity was probably invoked by a
            // different app. The preserves the "Up" functionality within the app according to
            // the activity hierarchy defined in AndroidManifest.xml via parentActivity
            // attributes.
            TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
            builder.addNextIntentWithParentStack(intent);
            builder.startActivities();
        } else {
            // Navigate normally to the manifest defined "Up" activity.
            NavUtils.navigateUpTo(currentActivity, intent);
        }
    }
}
 
Example 14
Project: MyAnimeViewer   File: AnimeDetailsActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        Intent upIntent = new Intent(this, MainActivity.class);
        if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
            // This activity is not part of the application's task, so create a new task
            // with a synthesized back stack.
            TaskStackBuilder.from(this)
                    .addNextIntent(upIntent)
                    .startActivities();
            finish();
        } else {
            // This activity is part of the application's task, so simply
            // navigate up to the hierarchical parent activity.
            NavUtils.navigateUpTo(this, upIntent);
        }
        return true;
    } else if (item.getTitle().equals("Settings")) {
        //startActivity(new Intent(this, Settings.class));
        finish();
        // overridePendingTransition(R.anim.hold, R.anim.push_out_to_left);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 15
Project: file_scanner   File: MainActivity.java   View source code 6 votes vote down vote up
private void showStartNotification() {
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(getString(R.string.file_scanner))
                    .setContentText(getString(R.string.scan_started))
                    .setTicker(getString(R.string.file_scan_started))
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    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(0, mBuilder.build());
}
 
Example 16
Project: android-mvvm-architecture   File: FeedActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 17
Project: 2017.1-Trezentos   File: ExamActivity.java   View source code 6 votes vote down vote up
private void sendEvaluationNotification(){
    NotificationCompat.Builder mBuilder =
            (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.trezentos_icon)
                    .setContentTitle("Avaliação")
                    .setContentText("Você tem avaliações à serem feitas!")
                    .setLargeIcon(BitmapFactory.decodeResource(getResources()
                            , R.drawable.trezentos_icon));

    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(0, mBuilder.build());
}
 
Example 18
Project: android-mvp-architecture   File: FeedActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 19
Project: boohee_v5.6   File: AppCompatActivity.java   View source code 6 votes vote down vote up
public boolean onSupportNavigateUp() {
    Intent upIntent = getSupportParentActivityIntent();
    if (upIntent == null) {
        return false;
    }
    if (supportShouldUpRecreateTask(upIntent)) {
        TaskStackBuilder b = TaskStackBuilder.create(this);
        onCreateSupportNavigateUpTaskStack(b);
        onPrepareSupportNavigateUpTaskStack(b);
        b.startActivities();
        try {
            ActivityCompat.finishAffinity(this);
        } catch (IllegalStateException e) {
            finish();
        }
    } else {
        supportNavigateUpTo(upIntent);
    }
    return true;
}
 
Example 20
Project: TheNounProject   File: IconsActivity.java   View source code 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            Intent upIntent = NavUtils.getParentActivityIntent(this);
            upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                TaskStackBuilder.create(this)
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            } else {
                NavUtils.navigateUpTo(this, upIntent);
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 21
Project: Programmers   File: CustomNotification.java   View source code 6 votes vote down vote up
private PendingIntent getCommentPendingIntent(Bundle b) {
    // Intent to open Comments Activity
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(CommentsActivity.class);

    Intent commentsIntent = IntentUtils.getIntent(context, CommentsActivity.class);
    commentsIntent.putExtras(b);
    stackBuilder.addNextIntent(commentsIntent);

    // Set the pendingIntent on Notification.Builder
    //PendingIntent pendingIntent = PendingIntent.getActivity(context, id, commentsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 22
Project: eggs-android   File: MainActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 23
Project: healthgo   File: StepService.java   View source code 6 votes vote down vote up
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());
}
 
Example 24
Project: background-location-updates-android-o   File: LocationResultHelper.java   View source code 6 votes vote down vote up
/**
 * Displays a notification with the location results.
 */
void showNotification() {
    Intent notificationIntent = new Intent(mContext, MainActivity.class);

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

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

    Notification.Builder notificationBuilder = new Notification.Builder(mContext)
            .setContentTitle(getLocationResultTitle())
            .setContentText(getLocationResultText())
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true)
            .setContentIntent(notificationPendingIntent);

    getNotificationManager().notify(0, notificationBuilder.build());
}
 
Example 25
Project: ulogger-android   File: LoggerService.java   View source code 6 votes vote down vote up
/**
 * Show notification
 *
 * @param mId Notification Id
 */
private void showNotification(int mId) {
    if (Logger.DEBUG) { Log.d(TAG, "[showNotification " + mId + "]"); }

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_stat_notify_24dp)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(String.format(getString(R.string.is_running), getString(R.string.app_name)));
    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);
    mNotificationManager.notify(mId, mBuilder.build());
}
 
Example 26
Project: mimi-reader   File: PostItemDetailActivity.java   View source code 6 votes vote down vote up
@Override
public void onClick(View v) {
    // This ID represents the Home or Up button. In the case of this
    // activity, the Up button is shown. Use NavUtils to allow users
    // to navigate up one level in the application structure. For
    // more details, see the Navigation pattern on Android Design:
    //
    // http://developer.android.com/design/patterns/navigation.html#up-vs-back
    //
    final Intent listIntent = new Intent(this, PostItemListActivity.class);
    if (NavUtils.shouldUpRecreateTask(this, listIntent)) {
        final TaskStackBuilder taskStack = TaskStackBuilder.create(this);
        taskStack.addNextIntent(listIntent);
        taskStack.startActivities();
    } else {
        NavUtils.navigateUpTo(this, listIntent);
    }
}
 
Example 27
Project: rview   File: ActivityHelper.java   View source code 6 votes vote down vote up
public static boolean performFinishActivity(Activity activity, boolean forceNavigateUp) {
    if (activity == null) {
        return false;
    }
    boolean hasParent = activity.getIntent().getBooleanExtra(Constants.EXTRA_HAS_PARENT, false);
    if (forceNavigateUp || !hasParent) {
        Intent upIntent = NavUtils.getParentActivityIntent(activity);
        if (upIntent != null) {
            if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
                TaskStackBuilder.create(activity)
                        .addNextIntentWithParentStack(upIntent)
                        .startActivities();
            } else {
                activity.startActivity(upIntent);
            }
        }
    }
    activity.finish();
    return true;
}
 
Example 28
Project: 2015-Google-I-O-app   File: TaskStackBuilderProxyActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    Intent proxyIntent = getIntent();
    if (!proxyIntent.hasExtra(EXTRA_INTENTS)) {
        finish();
        return;
    }

    for (Parcelable parcelable : proxyIntent.getParcelableArrayExtra(EXTRA_INTENTS)) {
        builder.addNextIntent((Intent) parcelable);
    }

    builder.startActivities();
    finish();
}
 
Example 29
Project: mobile-messaging-sdk-android   File: DeepLinkLandingActivity.java   View source code 6 votes vote down vote up
private void processDeepLink() {
    Intent intent = getIntent();
    if (intent == null || intent.getData() == null) {
        return;
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    List<String> segments = intent.getData().getPathSegments();
    if (segments.isEmpty()) {
        Intent launcherIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        if (launcherIntent != null) {
            startActivity(launcherIntent.putExtras(intent));
        }
        return;
    }

    for (String segment : intent.getData().getPathSegments()) {
        if (activityMap.containsKey(segment)) {
            Intent nextIntent = new Intent(this, activityMap.get(segment)).putExtras(intent);
            stackBuilder.addNextIntent(nextIntent);
        }
    }
    stackBuilder.startActivities();
}
 
Example 30
Project: toshi-android-client   File: ChatNotification.java   View source code 6 votes vote down vote up
private PendingIntent getPendingIntent(final Intent mainIntent, final Intent chatIntent) {
    final PendingIntent nextIntent = TaskStackBuilder.create(BaseApplication.get())
            .addParentStack(MainActivity.class)
            .addNextIntent(mainIntent)
            .addNextIntent(chatIntent)
            .getPendingIntent(getTitle().hashCode(), PendingIntent.FLAG_UPDATE_CURRENT);

    final Intent splashIntent =  new Intent(BaseApplication.get(), SplashActivity.class)
            .putExtra(SplashActivity.EXTRA__NEXT_INTENT, nextIntent);

    return PendingIntent.getActivity(
            BaseApplication.get(),
            UUID.randomUUID().hashCode(),
            splashIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 31
Project: messengerxmpp   File: NotificationService.java   View source code 6 votes vote down vote up
private PendingIntent createContentIntent(final String conversationUuid, final String downloadMessageUuid) {
	final TaskStackBuilder stackBuilder = TaskStackBuilder
			.create(mXmppConnectionService);
	stackBuilder.addParentStack(ConversationActivity.class);

	final Intent viewConversationIntent = new Intent(mXmppConnectionService,
			ConversationActivity.class);
	if (downloadMessageUuid != null) {
		viewConversationIntent.setAction(ConversationActivity.ACTION_DOWNLOAD);
	} else {
		viewConversationIntent.setAction(Intent.ACTION_VIEW);
	}
	if (conversationUuid != null) {
		viewConversationIntent.putExtra(ConversationActivity.CONVERSATION, conversationUuid);
		viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
	}
	if (downloadMessageUuid != null) {
		viewConversationIntent.putExtra(ConversationActivity.MESSAGE, downloadMessageUuid);
	}

	stackBuilder.addNextIntent(viewConversationIntent);

	return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 32
Project: Udacity-Capstone-Project   File: WorkoutWidgetProvider.java   View source code 6 votes vote down vote up
private RemoteViews updateWidgetListView(Context context, int appWidgetId) {
    RemoteViews remoteViews = new RemoteViews(
            context.getPackageName(), R.layout.widget_collection);
    Intent svcIntent = new Intent(context, WorkoutWidgetService.class);
    svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    svcIntent.setData(Uri.parse(
            svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
    remoteViews.setRemoteAdapter(R.id.listViewWidget,
            svcIntent);
    remoteViews.setEmptyView(R.id.listViewWidget, R.id.empty_view);
    Intent clickIntentTemplate = new Intent(context, LaunchActivity.class);
    PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
            .addNextIntentWithParentStack(clickIntentTemplate)
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.listViewWidget, clickPendingIntentTemplate);
    return remoteViews;
}
 
Example 33
Project: Capstoneproject1   File: RedWidgetProvider.java   View source code 6 votes vote down vote up
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    for (int appWidgetId : appWidgetIds) {
        RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_small);
        views.setImageViewResource(R.id.widget_icon, R.drawable.redchillies);
        // Create an Intent to launch MainActivity
        Intent intent = new Intent(context, ViewSummary.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);
        // Set up the collection
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            setRemoteAdapter(context, views);
        } else {
            setRemoteAdapterV11(context, views);
        }
        Intent clickIntentTemplate = new Intent(context, ViewSummary.class);
        PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context)
                .addNextIntentWithParentStack(clickIntentTemplate)
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate);
        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
Example 34
Project: android-common   File: SimpleFragmentActivityImpl.java   View source code 6 votes vote down vote up
@Override
public void onBackPressed() {
  Intent upIntent = NavUtils.getParentActivityIntent(this);
  if (upIntent != null) {
    if (NavUtils.shouldUpRecreateTask(this, upIntent) || isTaskRoot()) {
      // 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.
      if (!fragment.onBackPressed()) {
        ActivityCompat.finishAfterTransition(this);
      }
    }
  } else {
    if (!fragment.onBackPressed()) {
      ActivityCompat.finishAfterTransition(this);
    }
  }
}
 
Example 35
Project: android-oss   File: PushNotifications.java   View source code 6 votes vote down vote up
private @NonNull PendingIntent projectUpdateContentIntent(final @NonNull PushNotificationEnvelope envelope,
  final @NonNull Update update, final @NonNull String projectParam) {

  final Intent projectIntent = new Intent(this.context, ProjectActivity.class)
    .putExtra(IntentKey.PROJECT_PARAM, projectParam);

  final Intent updateIntent = new Intent(this.context, UpdateActivity.class)
    .putExtra(IntentKey.PROJECT_PARAM, projectParam)
    .putExtra(IntentKey.UPDATE, update)
    .putExtra(IntentKey.PUSH_NOTIFICATION_ENVELOPE, envelope);

  final TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this.context)
    .addNextIntentWithParentStack(projectIntent)
    .addNextIntent(updateIntent);

  return taskStackBuilder.getPendingIntent(envelope.signature(), PendingIntent.FLAG_UPDATE_CURRENT);
}
 
Example 36
Project: msf_communique   File: MyFirebaseMessagingService.java   View source code 6 votes vote down vote up
/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification( String messageBody) {

    Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("menuFragment",""+ messageBody);
    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(getApplicationContext());
    taskStackBuilder.addNextIntent(intent);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle("MSF Communique")
            .setContentText(""+messageBody.split("=")[1].replace("}", ""))
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

}
 
Example 37
Project: SmallPatch   File: WebActivity.java   View source code 6 votes vote down vote up
@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);
}
 
Example 38
Project: q-mail   File: NotificationActionCreator.java   View source code 5 votes vote down vote up
private TaskStackBuilder buildAccountsBackStack() {
    TaskStackBuilder stack = TaskStackBuilder.create(context);
    if (!skipAccountsInBackStack()) {
        Intent intent = new Intent(context, Accounts.class);
        intent.putExtra(Accounts.EXTRA_STARTUP, false);

        stack.addNextIntent(intent);
    }
    return stack;
}
 
Example 39
Project: q-mail   File: NotificationActionCreator.java   View source code 5 votes vote down vote up
private TaskStackBuilder buildMessageListBackStack(Account account, String folderId) {
    TaskStackBuilder stack = skipFolderListInBackStack(account, folderId) ?
            buildAccountsBackStack() : buildFolderListBackStack(account);

    LocalSearch search = new LocalSearch(folderId);
    search.addAllowedFolder(folderId);
    search.addAccountUuid(account.getUuid());
    Intent intent = MessageList.intentDisplaySearch(context, search, false, true, true);

    stack.addNextIntent(intent);

    return stack;
}
 
Example 40
Project: q-mail   File: NotificationActionCreator.java   View source code 5 votes vote down vote up
private TaskStackBuilder buildMessageViewBackStack(MessageReference message) {
    Account account = Preferences.getPreferences(context).getAccount(message.getAccountUuid());
    String folderId = message.getFolderId();
    TaskStackBuilder stack = buildMessageListBackStack(account, folderId);

    Intent intent = MessageList.actionDisplayMessageIntent(context, message);

    stack.addNextIntent(intent);

    return stack;
}