Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:ms.globalclass.netty.SecureChatClientHandler.java

@Override
public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
    if (MainTabActivity.instance != null) {
        MainTabActivity.instance.timer2.cancel();
        MainTabActivity.instance.timer2 = null;
        System.out.println("netty");
        if (MainTabActivity.instance.isInetnState())//
        {/* w w  w  .java2 s.c o  m*/
            context.stopService(new Intent(context, MyService.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));

            context.startService(new Intent(context, MyService.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        }
    }
    super.channelDisconnected(ctx, e);
}

From source file:be.ehb.fallwear.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//from w  ww.j  ava 2  s  .c o  m
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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_stat_ic_notification).setContentTitle("GCM Message")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.appzoneltd.lastmile.customer.deprecated.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///w w w  .  j a va 2s.  c  o m
private static void generateNotification(Context context, String message) {
    NotificationCompat.Builder notification;
    String title = context.getString(R.string.app_name);
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    notification = new NotificationCompat.Builder(context);
    notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher));
    notification.setSmallIcon(R.mipmap.ic_launcher);
    notification.setContentTitle(title);
    notification.setContentText(message);
    Intent notificationIntent = new Intent(context, PushNotificationActivity.class);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setContentIntent(intent);
    notification.setAutoCancel(true);
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationManager.notify(1, notification.build());
}

From source file:fr.bmartel.android.tictactoe.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//from w w  w . j a v  a 2 s .c  o  m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {

    String message = data.getString("message");

    if (from.startsWith("/topics/" + GameSingleton.DEVICE_ID)) {
        Log.d(TAG, "Message: " + message);

        try {

            JSONObject object = new JSONObject(message);

            ArrayList<String> eventItem = new ArrayList<>();
            eventItem.add(object.toString());

            broadcastUpdateStringList(BroadcastFilters.EVENT_MESSAGE, eventItem);

            if (!GameSingleton.activityForeground) {

                if (object.has(RequestConstants.DEVICE_MESSAGE_TOPIC)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID)
                        && object.has(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME)) {

                    GameMessageTopic topic = GameMessageTopic
                            .getTopic(object.getInt(RequestConstants.DEVICE_MESSAGE_TOPIC));

                    ChallengeMessage challengeMessage = new ChallengeMessage(topic,
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_ID),
                            object.getString(RequestConstants.DEVICE_MESSAGE_CHALLENGER_NAME));

                    Log.i(TAG, "challenged by " + challengeMessage.getChallengerName() + " : "
                            + challengeMessage.getChallengerId());

                    Intent intent2 = new Intent(this, DeviceListActivity.class);
                    intent2.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent2,
                            PendingIntent.FLAG_ONE_SHOT);
                    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Fight!")
                            .setContentText("challenged by " + challengeMessage.getChallengerName())
                            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
                    NotificationManager notificationManager = (NotificationManager) getSystemService(
                            Context.NOTIFICATION_SERVICE);
                    notificationManager.notify(new Random().nextInt(9999), notificationBuilder.build());

                    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                    boolean isScreenOn = pm.isScreenOn();
                    if (isScreenOn == false) {
                        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK
                                | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "MyLock");
                        wl.acquire(10000);
                        PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                                "MyCpuLock");
                        wl_cpu.acquire(10000);
                    }

                    GameSingleton.pendingChallengeMessage = challengeMessage;
                    GameSingleton.pendingChallenge = true;
                }
            }

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

        }
    }
}

From source file:ca.justinrichard.link.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w ww  . j  a va  2  s .  co  m*/
private void sendNotification(String messageBody, String linkId) {

    Intent intent;
    if (linkId.equals("")) {
        intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } else {
        intent = new Intent(this, LinkActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(LINK_ID, linkId);
    }

    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_link).setColor(getResources().getColor(R.color.colorPrimary))
            .setContentTitle("Link request").setContentText(messageBody).setAutoCancel(true)
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:br.ufc.quixada.dsdm.myapplicationtestemulttabs.googleGCM.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   ww w  .j  a  v a2 s  . c om*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, MainActivityTabMensagens.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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.mensageiro_icon).setContentTitle("MENSSAGEIRO").setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:asia.covisoft.goom.gcm.GoOmUserGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.//  w  ww . j a v a2 s. c  o  m
 */
private void sendNotification(String message, Driverconfirm response) {

    Intent intent = new Intent(this, HistoryDetailsActivity.class);
    trandingId = response.getTradingid();
    intent.putExtra(Extras.TRADING_ID, trandingId);
    intent.putExtra(Extras.HISTORY_STATE, false);
    if (response.getValue().equals("tip")) {
        intent.putExtra(Extras.REQUEST_TIP, true);
        intent.putExtra(Extras.MAX_TIP, response.getMaxsuggest());
        intent.putExtra(Extras.MIN_TIP, response.getMinsuggest());
        cancelTip();
    }

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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_stat_ic_notification).setContentTitle(getString(R.string.app_name_full))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.androdevlinux.percy.bitfly.Core.Services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//* w w  w  .  j av a2s  . c o  m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    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_menu_camera).setContentTitle("FCM Message").setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.rossier.shclechelles.service.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w w w . j a  va  2  s  .  c  om*/
 */
private void sendNotification(String from, String message) {
    Gson gson = new GsonBuilder().create();
    String messageUTF8 = "";
    try {
        messageUTF8 = new String(message.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    Log.i("MyGCMListenerService", message);
    Log.i("MyGCMListenerService", messageUTF8);
    if (messageUTF8 == "")
        return;
    MatchNotification match = gson.fromJson(messageUTF8, MatchNotification.class);
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    int icon = R.drawable.ic_launcher_shc;
    long when = System.currentTimeMillis();
    // Notification notification = new Notification(icon, "Nouveaux rsultats", when);
    Notification notification = new Notification.Builder(this.getBaseContext())
            .setContentText("Nouveaux rsultats").setSmallIcon(icon).setWhen(when).build();

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.match_notif_layout);
    contentView.setTextViewText(R.id.notif_team_home, match.getTeam_home());
    contentView.setTextViewText(R.id.notif_team_away, match.getTeam_away());
    contentView.setTextViewText(R.id.notif_result_home, match.getResult_home() + "");
    contentView.setTextViewText(R.id.notif_result_away, match.getResult_away() + "");
    contentView.setTextViewText(R.id.notif_ligue, match.getLigue());
    contentView.setImageViewResource(R.id.notif_team_loc_logo, Utils.getLogo(match.getTeam_home()));
    contentView.setImageViewResource(R.id.notif_team_away_logo, Utils.getLogo(match.getTeam_away()));
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(this, MainActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;

    //notification.flags |= Notification.FLAG_ONGOING_EVENT; //Do not clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    //get topics name
    String[] topic = from.split("/");

    mNotificationManager.notify(topic[2].hashCode(), notification);
}

From source file:org.bfr.periodicquery.PeriodicQueryService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    // The intent to launch when the user clicks the expanded notification
    Intent launchIntent = new Intent(this, StartStopActivity.class);
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);

    // This constructor is deprecated. Use Notification.Builder instead
    Notification notice = new Notification(R.drawable.ic_launcher, "Periodic Query",
            System.currentTimeMillis());

    // This method is deprecated. Use Notification.Builder instead.
    notice.setLatestEventInfo(this, "Periodic Query", "Periodic Query", pendIntent);
    notice.flags |= Notification.FLAG_NO_CLEAR;

    startForeground(1234, notice);//from   ww  w .  j  av a  2 s  .com

    return START_STICKY;
}