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:Main.java

/**
 * Finish the given activity and start a home activity class.
 * <p/>/*w ww . ja  v  a 2  s  . c  o m*/
 * This mirror the behavior of the home action bar button that clears the
 * current activity and starts or brings another activity to the top.
 *
 * @param activity
 * @param homeActivityClass
 */
public static void goHome(Activity activity, Class<?> homeActivityClass) {
    activity.finish();
    Intent intent = new Intent(activity, homeActivityClass);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);
}

From source file:com.hkm.mmedic.utils.NotificationBuilder.java

public static Notification createServiceNotification(Context context, MediaMetadata metadata) {
    Intent notificationIntent = new Intent(context, MainActivity.class);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.setAction(Intent.ACTION_MAIN);

    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    final Notification notification = (new NotificationCompat.Builder(context))
            .setSmallIcon(R.mipmap.ic_launcher).setContentIntent(contentIntent).setTicker(null)
            .setContentTitle(metadata.getTitile()).setContentText(metadata.getArtist()).setOngoing(true)
            .setWhen(0).build();//w ww.j av a  2  s  . c  om

    return notification;
}

From source file:com.h6ah4i.android.example.openslmediaplayer.app.utils.NotificationBuilder.java

public static Notification createServiceNotification(Context context, MediaMetadata metadata) {
    Intent notificationIntent = new Intent(context, MainActivity.class);

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.setAction(Intent.ACTION_MAIN);

    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    final Notification notification = (new NotificationCompat.Builder(context))
            .setSmallIcon(R.drawable.ic_launcher).setContentIntent(contentIntent).setTicker(null)
            .setContentTitle(metadata.getTitile()).setContentText(metadata.getArtist()).setOngoing(true)
            .setWhen(0).build();//w ww. j  ava  2 s. c o m

    return notification;
}

From source file:Main.java

/**
 * Enables the NFC foreground dispatch system for the given Activity.
 * /*  w w w.j  a  v  a  2s .co m*/
 * @param targetActivity The Activity that is in foreground and wants to have NFC Intents.
 * @see #disableNfcForegroundDispatch(android.app.Activity)
 */
public static void enableNfcForegroundDispatch(Activity targetActivity) {
    if (mNfcAdapter != null && mNfcAdapter.isEnabled()) {

        Intent intent = new Intent(targetActivity, targetActivity.getClass())
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(targetActivity, 0, intent, 0);
        mNfcAdapter.enableForegroundDispatch(targetActivity, pendingIntent, null,
                new String[][] { new String[] { NfcA.class.getName() } });
    }
}

From source file:com.secupwn.aimsicd.utils.MiscUtils.java

public static void showNotification(Context context, String tickertext, String contentText,
        @DrawableRes int drawable_id, boolean auto_cancel) {
    int NOTIFICATION_ID = 1;

    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND);

    PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), drawable_id);
    Notification notification = new NotificationCompat.Builder(context).setSmallIcon(drawable_id)
            .setLargeIcon(largeIcon).setTicker(tickertext)
            .setContentTitle(context.getResources().getString(R.string.main_app_name))
            .setContentText(contentText).setOngoing(true).setAutoCancel(auto_cancel)
            .setContentIntent(contentIntent).build();
    NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification);
}

From source file:me.raatiniemi.worker.presentation.view.notification.BackupNotification.java

private static PendingIntent buildContentAction(Context context) {
    Intent intent = new Intent(context, ProjectsActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    return buildPendingIntentWithActivity(context, intent);
}

From source file:com.innoc.secureline.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, SecureLine.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:com.mindprotectionkit.freephone.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, RedPhone.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:com.linkbubble.ui.NotificationNewBraveBrowserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MainController mainController = MainController.get();
    if (mainController != null) {
        mainController.switchToBubbleView(false);
    }/*from  ww  w .ja v a  2  s . c  o  m*/
    try {
        Intent gpsIntent = new Intent(Intent.ACTION_VIEW);
        gpsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        gpsIntent.setData(Uri
                .parse("market://details?id=" + getResources().getString(R.string.tab_based_browser_id_name)));
        startActivity(gpsIntent);
    } catch (android.content.ActivityNotFoundException anfe) {
    }

    finish();
}

From source file:ca.rmen.android.scrumchatter.meeting.detail.MeetingActivity.java

public static void startMeeting(Context context, long meetingId) {
    Intent intent = new Intent(context, MeetingActivity.class);
    intent.putExtra(Meetings.EXTRA_MEETING_ID, meetingId);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    context.startActivity(intent);/*from  w w  w.  j a  v  a 2s . co  m*/
}