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.securecomcode.text.notifications.MessageNotifier.java

public static void notifyMessageDeliveryFailed(Context context, Recipients recipients, long threadId) {
    if (visibleThread == threadId) {
        sendInThreadNotification(context);
    } else {// w ww.  j  av a  2s  .co  m
        Intent intent = new Intent(context, RoutingActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("recipients", recipients);
        intent.putExtra("thread_id", threadId);
        intent.setData((Uri.parse("custom://" + System.currentTimeMillis())));

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        builder.setSmallIcon(R.drawable.icon_notification);
        builder.setLargeIcon(
                BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_action_warning_red));
        builder.setContentTitle(context.getString(R.string.MessageNotifier_message_delivery_failed));
        builder.setContentText(context.getString(R.string.MessageNotifier_failed_to_deliver_message));
        builder.setTicker(context.getString(R.string.MessageNotifier_error_delivering_message));
        builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, 0));
        builder.setAutoCancel(true);
        setNotificationAlarms(context, builder, true);

        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify((int) threadId,
                builder.build());
    }
}

From source file:com.mattermost.gcm.GcmMessageHandler.java

private void createNotification(boolean doAlert) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    if (doAlert) {
        defaults = defaults | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
    }/* w w w  . ja va  2 s.com*/

    Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, NotificationDismissReceiver.class), 0);

    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (channelIdToNotification.size() == 0) {
        mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES).setDefaults(defaults)
            .setContentIntent(contentIndent).setDeleteIntent(deleteIntent).setAutoCancel(true);

    if (channelIdToNotification.size() == 1) {
        Bundle data = channelIdToNotification.entrySet().iterator().next().getValue();
        String body = data.getString("message");
        mBuilder.setContentTitle("Mattermost").setContentText(body)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body));
    } else {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        String summaryTitle = String.format("Mattermost (%d)", channelIdToNotification.size());
        mBuilder.setContentTitle(summaryTitle);

        for (Bundle data : channelIdToNotification.values()) {
            style.addLine(data.getString("message"));
        }

        style.setBigContentTitle(summaryTitle);
        mBuilder.setStyle(style);
    }

    mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

From source file:eu.istvank.apps.lenslog.services.NotifySchedulingService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    //TODO: if user selects the main notification we should ask the question in the UI
    PendingIntent mainPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(this, MainActivity.class), 0);

    // YES/* ww w.j  a v a2 s  . c om*/
    Intent yesIntent = new Intent(this, MainActivity.class);
    yesIntent.putExtra(NOTIFICATION_WORN, true);
    yesIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent yesPendingIntent = PendingIntent.getActivity(this, MainActivity.REQUEST_YES, yesIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // NO
    Intent noIntent = new Intent(this, MainActivity.class);
    noIntent.putExtra(NOTIFICATION_WORN, false);
    noIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent noPendingIntent = PendingIntent.getActivity(this, MainActivity.REQUEST_NO, noIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setContentText(getString(R.string.notification_question))
            .addAction(R.drawable.ic_done_white, getString(R.string.yes), yesPendingIntent)
            .addAction(R.drawable.ic_close_white, getString(R.string.no), noPendingIntent);

    mBuilder.setContentIntent(mainPendingIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:info.tongrenlu.PlaybackControlsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_playback_controls, container, false);

    mPlayPause = (ImageButton) rootView.findViewById(R.id.play_pause);
    mPlayPause.setEnabled(true);//from   ww  w  .  j a  va  2s .c  o  m
    mPlayPause.setOnClickListener(mButtonListener);

    mTitle = (TextView) rootView.findViewById(R.id.title);
    mSubtitle = (TextView) rootView.findViewById(R.id.artist);
    mExtraInfo = (TextView) rootView.findViewById(R.id.extra_info);
    mAlbumArt = (ImageView) rootView.findViewById(R.id.album_art);
    rootView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), FullScreenPlayerActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        }
    });
    return rootView;
}

From source file:com.facebook.CustomTabActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = new Intent(this, CustomTabMainActivity.class);
    intent.setAction(CUSTOM_TAB_REDIRECT_ACTION);
    intent.putExtra(CustomTabMainActivity.EXTRA_URL, getIntent().getDataString());

    // these flags will open CustomTabMainActivity from the back stack as well as closing this
    // activity and the custom tab opened by CustomTabMainActivity.
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    startActivityForResult(intent, CUSTOM_TAB_REDIRECT_REQUEST_CODE);
}

From source file:com.ibm.bluelist.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SensoroManager sensoroManager = SensoroManager.getInstance(getApplicationContext());
    blApplication = (MessengerApplication) getApplication();
    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();/*  w ww . j a va  2 s . co  m*/
    }
    myIntent = new Intent(getApplicationContext(), PostTrackingNotifier.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if (sensoroManager.isBluetoothEnabled()) {
        /**
         * Enable cloud service (upload sensor data, including battery status, UMM, etc.)Without setup, it keeps in closed status as default.
         **/
        sensoroManager.setCloudServiceEnable(true);
        /**
         * Enable SDK service
         **/
        try {
            sensoroManager.startService();
        } catch (Exception e) {
            e.printStackTrace(); // Fetch abnormal info
        }
    } else {
        Intent bluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(bluetoothIntent, REQUEST_ENABLE_BT);
    }
    BeaconManagerListener beaconManagerListener = new BeaconManagerListener() {
        ArrayList<String> foundSensors = new ArrayList<String>();

        @Override
        public void onUpdateBeacon(ArrayList<Beacon> beacons) {
            // Refresh sensor info
            for (Beacon beacon : beacons) {
                if (true) {
                    if (beacon.getMovingState() == Beacon.MovingState.DISABLED) {
                        // Disable accelerometer
                        System.out.println(beacon.getSerialNumber() + "Disabled");
                        Log.d("Main", beacon.getSerialNumber() + "Disabled");

                    } else if (beacon.getMovingState() == Beacon.MovingState.STILL) {
                        // Device is at static
                        Log.d("Main", beacon.getSerialNumber() + "static");
                        Log.d("Main", beacon.getProximityUUID());
                        if (!foundSensors.contains(beacon.getProximityUUID())) {
                            //String messageDisplay = "";
                            Log.d("Main", "getting Beacon Info");
                            foundSensors.add(beacon.getProximityUUID());
                            IBMCloudCode.initializeService();
                            IBMCloudCode myCloudCodeService = IBMCloudCode.getService();
                            String id = beacon.getProximityUUID();
                            String url = "/getNotification?id=" + id;
                            myCloudCodeService.get(url).continueWith(new Continuation<IBMHttpResponse, Void>() {

                                @Override
                                public Void then(Task<IBMHttpResponse> task) throws Exception {
                                    if (task.isCancelled()) {
                                        Log.e(CLASS_NAME,
                                                "Exception : Task" + task.isCancelled() + "was cancelled.");
                                    } else if (task.isFaulted()) {
                                        Log.e(CLASS_NAME, "Exception : " + task.getError().getMessage());
                                    } else {
                                        InputStream is = task.getResult().getInputStream();
                                        try {
                                            BufferedReader in = new BufferedReader(new InputStreamReader(is));
                                            String responseString = "";
                                            String myString = "";
                                            while ((myString = in.readLine()) != null)
                                                responseString += myString;

                                            in.close();
                                            Log.i(CLASS_NAME, "Response Body: " + responseString);
                                            JSONObject obj = new JSONObject(responseString);
                                            final String name = obj.getString("message");
                                            final String meets = obj.getString("meetups");

                                            /*Notification*/

                                            myIntent.putExtra("response", responseString);
                                            PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                                                    getApplicationContext(), 5, myIntent,
                                                    PendingIntent.FLAG_UPDATE_CURRENT);
                                            final NotificationCompat.Builder builder = new NotificationCompat.Builder(
                                                    getApplicationContext());
                                            builder.setSmallIcon(R.drawable.logo);
                                            builder.setContentTitle("IBM Beacons Messenger");
                                            builder.setContentText(name);
                                            builder.setContentIntent(pendingNotificationIntent);
                                            NotificationManager notificationManager = (NotificationManager) getSystemService(
                                                    Context.NOTIFICATION_SERVICE);
                                            notificationManager.notify(5, builder.build());

                                        } catch (IOException e) {
                                            e.printStackTrace();
                                        }

                                        Log.i(CLASS_NAME, "Response Status from login: "
                                                + task.getResult().getHttpResponseCode());
                                    }

                                    return null;
                                }

                            });

                        }
                        Log.d("Main", beacon.getMajor().toString());
                        Log.d("Main", beacon.getMinor().toString());
                        //Log.d("Main",beacon.getRssi().toString());
                        System.out.println(beacon.getSerialNumber() + "static");

                    } else if (beacon.getMovingState() == Beacon.MovingState.MOVING) {
                        // Device is moving
                        Log.d("Main", beacon.getSerialNumber() + "moving");
                        Log.d("Main", beacon.getProximityUUID());
                        System.out.println(beacon.getSerialNumber() + "moving");
                    }
                }
            }
        }

        @Override
        public void onNewBeacon(Beacon beacon) {
            // New sensor found
            System.out.println(beacon.getSerialNumber());
            Log.d("Main", beacon.getSerialNumber() + "Got New");
        }

        @Override
        public void onGoneBeacon(Beacon beacon) {
            // A sensor disappears from the range
            System.out.println(beacon.getSerialNumber());

        }
    };
    sensoroManager.setBeaconManagerListener(beaconManagerListener);
}

From source file:com.envision_lightning.big_o.about.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    switch (item.getItemId()) {
    ////            // Respond to the action bar's Up/Home button
    case android.R.id.home:
        Intent intent = NavUtils.getParentActivityIntent(this);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        NavUtils.navigateUpTo(this, intent);
        return true;
    }//w  w  w  .j av a2 s .  c  o m
    return super.onOptionsItemSelected(item);
}

From source file:com.kth.baasio.startup.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from w  ww  . ja v a2s  .c om*/
private static void generateNotification(Context context, String message) {
    BaasioPayload msg = JsonUtils.parse(message, BaasioPayload.class);
    if (ObjectUtils.isEmpty(msg)) {
        return;
    }

    String alert = "";
    if (!ObjectUtils.isEmpty(msg.getAlert())) {
        alert = msg.getAlert().replace("\\r\\n", "\n");
    }

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(context, UnityPlayerActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(alert)
            .setContentIntent(intent).setTicker(alert).setAutoCancel(true).getNotification();

    notificationManager.notify(0, notification);
}

From source file:com.example.aapp.gcm.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//* w ww. j av a2 s . c o  m*/
@SuppressWarnings("deprecation")
private static void generateNotification(Context context, String message) {
    BaasioPayload msg = JsonUtils.parse(message, BaasioPayload.class);
    if (ObjectUtils.isEmpty(msg)) {
        return;
    }

    String alert = "";
    if (!ObjectUtils.isEmpty(msg.getAlert())) {
        alert = msg.getAlert().replace("\\r\\n", "\n");
    }

    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(context, MainActivity.class);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    Notification notification = new NotificationCompat.Builder(context).setWhen(when).setSmallIcon(icon)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(alert)
            .setContentIntent(intent).setTicker(alert).setAutoCancel(true).getNotification();
    notificationManager.notify("Popbell", context.getResources().getInteger(R.integer.notiid), notification);
}

From source file:com.villetainio.travelcardreminder.activities.MainActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), ReadCardActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);//from w  w w . j a v  a  2 s .  c  om

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};

    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType("*/*"); //TODO Use only needed MIME based dispatches.
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("MIME type not supported.");
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}