Example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP

Introduction

In this page you can find the example usage for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.

Prototype

int FLAG_ACTIVITY_SINGLE_TOP

To view the source code for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.

Click Source Link

Document

If set, the activity will not be launched if it is already running at the top of the history stack.

Usage

From source file:com.yutong.axxc.parents.view.common.ActivityUtils.java

/**
 * activity/*from   w w w . j ava 2s. co m*/
 * @param from ?activity
 * @param to activity
 * @param extras ??
 */
public static void changeActivity(Activity from, Class<?> to, Bundle extras) {
    // Intent intent = setIntent(from, to, extras);
    Intent intent = new Intent();
    if (extras != null)
        intent.putExtras(extras);
    intent.setClass(from.getBaseContext(), to);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    from.startActivity(intent);
    //from.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    from.overridePendingTransition(R.anim.enter_righttoleft, R.anim.exit_righttoleft);
}

From source file:br.ajmarques.cordova.plugin.localnotification.ReceiverActivity.java

/**
 * Launch main intent for package./* w  w w . j  av  a 2 s . co  m*/
 */
private void launchMainIntent() {
    Context context = getApplicationContext();
    String packageName = context.getPackageName();
    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);

    launchIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    context.startActivity(launchIntent);
}

From source file:info.zamojski.soft.towercollector.updater.UpdaterNotificationHelper.java

private PendingIntent createMainActivityResultIntent(UpdateInfo updateInfo) {
    Intent intent = new Intent(MyApplication.getApplication(), MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.setAction(UpdateCheckAsyncTask.TASK_FULL_NAME + "_NID_" + UpdateCheckAsyncTask.NOTIFICATION_ID);
    intent.putExtra(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO, updateInfo);
    PendingIntent pendingIntent = PendingIntent.getActivity(MyApplication.getApplication(), 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
}

From source file:com.google.android.apps.iosched.gcm.command.AnnouncementCommand.java

private void displayNotification(Context context, String message) {
    LOGI(TAG, "Displaying notification: " + message);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.ic_stat_notification).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, HomeActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))//from www .  j ava2 s  .c  o m
                    .setAutoCancel(true).build());
}

From source file:augsburg.se.alltagsguide.gcm.command.AnnouncementCommand.java

private void displayNotification(Context context, String message) {
    Ln.i("Displaying notification: " + message);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setColor(ContextCompat.getColor(context, R.color.primary))
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, OverviewActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))/*from  w  w w.  ja  va 2  s  .c  o  m*/
                    .setAutoCancel(true).build());
}

From source file:com.aqtx.app.main.activity.MainActivity.java

public static void start(Context context, Intent extras) {
    Intent intent = new Intent();
    intent.setClass(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    if (extras != null) {
        intent.putExtras(extras);/* w w  w  .j a v a  2s .  c  om*/
    }
    context.startActivity(intent);
}

From source file:org.aankor.animenforadio.RadioNotification.java

public RadioNotification(final Service s) {
    this.service = s;
    this.context = s.getApplicationContext();
    Intent main = new Intent(context, Main.class);
    main.setFlags(// w w w  .  j a v  a2s .  co  m
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    init();

    builder = new NotificationCompat.Builder(context)
            .setContentIntent(PendingIntent.getActivity(context, 0, main, 0)).setTicker("AnimeNfo Radio Player")
            .setSmallIcon(R.drawable.ic_launcher).setOngoing(true);
}

From source file:com.google.android.gcm.demo.app.utils.Commons.java

private static PendingIntent buildPendingIntent(Context context) {
    Intent notificationIntent = new Intent(context, DemoActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(context, 0, notificationIntent, 0);
}

From source file:com.conferenceengineer.android.iosched.gcm.command.AnnouncementCommand.java

private void displayNotification(Context context, String message) {
    LOGI(TAG, "Displaying notification: " + message);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.drawable.conference_ic_notification).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, HomeActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))//from www .j  ava  2 s.  c  o  m
                    .setAutoCancel(true).build());
}

From source file:com.example.android.customnotifications.MainActivity.java

/**
 * This sample demonstrates notifications with custom content views.
 *
 * <p>On API level 16 and above a big content view is also defined that is used for the
 * 'expanded' notification. The notification is created by the NotificationCompat.Builder.
 * The expanded content view is set directly on the {@link android.app.Notification} once it has been build.
 * (See {@link android.app.Notification#bigContentView}.) </p>
 *
 * <p>The content views are inflated as {@link android.widget.RemoteViews} directly from their XML layout
 * definitions using {@link android.widget.RemoteViews#RemoteViews(String, int)}.</p>
 *//*  w w w.  j  av  a 2 s . c  o m*/
private void createNotification() {
    // BEGIN_INCLUDE(notificationCompat)
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    // END_INCLUDE(notificationCompat)

    // BEGIN_INCLUDE(intent)
    //Create Intent to launch this Activity again if the notification is clicked.
    Intent i = new Intent(this, MainActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(intent);
    // END_INCLUDE(intent)

    // BEGIN_INCLUDE(ticker)
    // Sets the ticker text
    builder.setTicker(getResources().getString(R.string.custom_notification));

    // Sets the small icon for the ticker
    builder.setSmallIcon(R.drawable.ic_stat_custom);
    // END_INCLUDE(ticker)

    // BEGIN_INCLUDE(buildNotification)
    // Cancel the notification when clicked
    builder.setAutoCancel(true);

    // Build the notification
    Notification notification = builder.build();
    // END_INCLUDE(buildNotification)

    // BEGIN_INCLUDE(customLayout)
    // Inflate the notification layout as RemoteViews
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification);

    // Set text on a TextView in the RemoteViews programmatically.
    final String time = DateFormat.getTimeInstance().format(new Date()).toString();
    final String text = getResources().getString(R.string.collapsed, time);
    contentView.setTextViewText(R.id.textView, text);

    /* Workaround: Need to set the content view here directly on the notification.
     * NotificationCompatBuilder contains a bug that prevents this from working on platform
     * versions HoneyComb.
     * See https://code.google.com/p/android/issues/detail?id=30495
     */
    notification.contentView = contentView;

    // Add a big content view to the notification if supported.
    // Support for expanded notifications was added in API level 16.
    // (The normal contentView is shown when the notification is collapsed, when expanded the
    // big content view set here is displayed.)
    if (Build.VERSION.SDK_INT >= 16) {
        // Inflate and set the layout for the expanded notification view
        RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
        notification.bigContentView = expandedView;
    }
    // END_INCLUDE(customLayout)

    // START_INCLUDE(notify)
    // Use the NotificationManager to show the notification
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(0, notification);
    // END_INCLUDE(notify)
}