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.company.millenium.iwannask.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param data GCM message received.//from w ww .  j  av  a2 s  .c  o  m
 */
private void sendNotification(Bundle data) {
    String question_body = data.getString("question_body");
    String answer_body = data.getString("answer_body");
    String question_id = data.getString("question_id");
    //String answer_id = data.getString("answer_id");
    String user_name = data.getString("user_name");
    if (user_name != null && user_name.contains(" ")) {
        user_name = user_name.split(" ")[0];
    }
    String type = data.getString("type");

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("url", "/questions/" + question_id);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    String info = " answered:";
    if (type != null && type.contentEquals("answer_feedback")) {
        String isLiked = data.getString("feedback_value");
        info = " disliked your answer";
        if (isLiked != null && isLiked.equals("true")) {
            info = " liked your answer";
        }
    } else if (type != null && type.contentEquals("question_answer_op")) {
        info = " commented on";
    }
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_comment_question_outline_grey600_36dp).setContentTitle(user_name + info)
            .setContentText(question_body)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(question_body + "\n" + answer_body))
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(id, notificationBuilder.build());
    id = id + 1;
}

From source file:com.codebutler.farebot.activities.MainActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getActionBar();
    actionBar.setHomeButtonEnabled(false);

    mDataCache = new HashMap<String, TransitIdentity>();

    registerForContextMenu(getListView());

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Intent intent = new Intent(this, ReadingTagActivity.class);
    intent.addFlags(//from   w w  w. j  a v a 2s .c  o  m
            Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    mTechLists = new String[][] { new String[] { IsoDep.class.getName() },
            new String[] { MifareClassic.class.getName() }, new String[] { MifareUltralight.class.getName() },
            new String[] { NfcF.class.getName() } };

    setListAdapter(new CardsAdapter());
    getLoaderManager().initLoader(0, null, this);
}

From source file:de.stadtrallye.rallyesoft.model.AndroidNotificationManager.java

@Override
public void updateChatNotification(IChatroom chatroom) {

    Map<IChatroom, List<ChatEntry>> notifyingEntries = new HashMap<>();
    List<ChatEntry> unread = chatroom.getUnreadEntries();
    if (unread.size() > 0)
        notifyingEntries.put(chatroom, unread);

    if (notifyingEntries.size() > 0) {

        String heading, summary;//from w ww  .ja  v a  2 s . co  m
        int count;
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        //Notification for one chatroom
        if (notifyingEntries.size() == 1) {
            IChatroom room = notifyingEntries.keySet().iterator().next();
            List<ChatEntry> entries = notifyingEntries.get(room);

            Intent intent = new Intent(context, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.putExtra(Std.TAB, Std.CHATROOM);
            intent.putExtra(Std.CHATROOM, room.getID());
            intent.putExtra(Std.CHAT_ID, entries.get(0).chatID);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            heading = context.getString(R.string.new_messages_in) + " " + room.getName();

            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            for (ChatEntry chatEntry : entries) {

                inboxStyle.addLine(Html.fromHtml("<b>" + chatEntry.getUserName() + " ("
                        + chatEntry.getGroupName() + "):</b> " + chatEntry.message));
            }
            count = entries.size();

            summary = count + " " + context.getString(R.string.x_new_messages);

            builder.setStyle(inboxStyle).setContentIntent(pendingIntent);

        } else { //Multiple Chatrooms
            Intent intent = new Intent(context, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.putExtra(Std.TAB, Std.CHATROOM);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            count = 0;
            heading = context.getString(R.string.new_messages);

            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            for (IChatroom room : notifyingEntries.keySet()) {
                int size = notifyingEntries.get(room).size();
                inboxStyle.addLine(room.getName() + " (" + size + ")");
                count += size;
            }

            summary = context.getString(R.string.x_new_messages_in_y_chatrooms, count, notifyingEntries.size());

            builder.setContentIntent(pendingIntent).setStyle(inboxStyle);

        }

        builder.setNumber(count).setSmallIcon(android.R.drawable.stat_notify_chat).setContentTitle(heading)
                .setSubText(summary).setLights(Color.CYAN, 500, 500);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        builder.setSound(alarmSound);

        notificationService.notify("chat notification", Std.CHAT_NOTIFICATION, builder.build());
    } else
        notificationService.cancel("chat notification", Std.CHAT_NOTIFICATION);
}

From source file:com.camera.simplewebcam.push.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();//from   w w w  .j  a  v a2 s.com
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.e(TAG, "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());
            Log.i(TAG, "Received: " + extras.getString("text"));

            Intent sendIntent = new Intent(getApplicationContext(), Main.class);
            sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT, extras.getString("text"));
            startActivity(sendIntent);
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}

From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java

private void sendNotification(String messageTitle, String messageBody) {
    Intent intent = MainActivity.makeIntent(this);
    intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(messageTitle);
    bigTextStyle.bigText(messageBody);/*ww  w  .  ja  va2s.c o m*/

    Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle)
            .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true)
            .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200)
            .setPriority(Notification.PRIORITY_MAX);

    //for vibration
    Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(1000);

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

    long time = new Date().getTime();
    String tmpStr = String.valueOf(time);
    String last4Str = tmpStr.substring(tmpStr.length() - 5);
    int notificationId = Integer.valueOf(last4Str);

    notificationManager.notify(notificationId, notificationBuilder.build());
}

From source file:com.irateam.vkplayer.notifications.PlayerNotificationFactory.java

public PlayerNotificationFactory(Context context) {
    this.context = context;
    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    playerPreviousAction = new Action.Builder(R.drawable.ic_notification_prev_white_24dp,
            context.getString(R.string.notification_previous), createPendingIntent(PlayerService.PREVIOUS))
                    .build();// ww w. j  a  va2  s  .  co m

    playerNextAction = new Action.Builder(R.drawable.ic_notification_next_white_24dp,
            context.getString(R.string.notification_next), createPendingIntent(PlayerService.NEXT)).build();

    playerPlayAction = new Action.Builder(R.drawable.ic_notification_play_white_24dp,
            context.getString(R.string.notification_resume), createPendingIntent(PlayerService.RESUME)).build();

    playerPauseAction = new Action.Builder(R.drawable.ic_notification_pause_white_24dp,
            context.getString(R.string.notification_pause), createPendingIntent(PlayerService.PAUSE)).build();

    style = new NotificationCompat.MediaStyle().setShowCancelButton(true)
            .setCancelButtonIntent(createPendingIntent(PlayerService.STOP)).setShowActionsInCompactView(1, 2);

    Intent contentIntent = new Intent(context, AudioActivity.class);
    contentIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    builder = new NotificationCompat.Builder(context);
    builder.setStyle(style).setPriority(Notification.PRIORITY_HIGH).setWhen(0)
            .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)).setAutoCancel(true)
            .addAction(playerPreviousAction).addAction(playerPlayAction).addAction(playerNextAction);

}

From source file:com.nadmm.airports.DrawerActivityBase.java

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

    setContentView();/*from w  w  w . j a v a2  s.  c  o  m*/

    Toolbar toolbar = getActionBarToolbar();

    mDrawerList = (DrawerListView) findViewById(R.id.left_drawer);
    mDrawerList.setOnItemClickListener(this);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close) {

        public void onDrawerClosed(View view) {
            ActionBar actionBar = getSupportActionBar();
            actionBar.setNavigationMode(mNavMode);
            actionBar.setTitle(mTitle);
            actionBar.setSubtitle(mSubtitle);
            if (actionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST) {
                actionBar.setDisplayShowTitleEnabled(false);
            }
            supportInvalidateOptionsMenu();

            if (mIntent != null) {
                mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                mIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(mIntent);
                mIntent = null;
            }
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            ActionBar actionBar = getSupportActionBar();
            mTitle = actionBar.getTitle();
            mSubtitle = actionBar.getSubtitle();
            mNavMode = actionBar.getNavigationMode();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setTitle(R.string.app_name);
            actionBar.setSubtitle(null);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.color_primary));
}

From source file:com.android.calendar.selectcalendars.SelectVisibleCalendarsActivity.java

public void handleSelectSyncedCalendarsClicked(View v) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClass(this, SelectSyncedCalendarsMultiAccountActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    startActivity(intent);/*  www .  j  a  v a2  s  . c  o m*/
}

From source file:com.example.karan.bookdemo.chat.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from  w  w w. j a v  a 2s. com
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, ChatList.class).putExtra("data", message).putExtra("sender", Sender);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, new Random().nextInt() /* Request code */,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("From:" + Sender).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(new Random().nextInt() /* ID of notification */, notificationBuilder.build());
}