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:nuclei.media.MediaNotificationManager.java

private PendingIntent createContentIntent(MediaDescriptionCompat description) {
    try {/* www  .  ja v  a 2 s  .com*/
        MediaId id = MediaProvider.getInstance().getMediaId(description.getMediaId());
        Intent openUI = new Intent(mService,
                id.type == MediaId.TYPE_AUDIO ? Configuration.AUDIO_ACTIVITY : Configuration.VIDEO_ACTIVITY);
        openUI.putExtra(MediaService.MEDIA_ID, description.getMediaId());
        openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT);
    } catch (Exception err) {
        throw new RuntimeException(err);
    }
}

From source file:im.neon.activity.VectorRoomDetailsActivity.java

@Override
protected void onResume() {
    super.onResume();

    if (mSession.isAlive()) {
        // check if the room has been left from another client
        if ((null == mRoom.getMember(mSession.getMyUserId()))
                || !mSession.getDataHandler().doesRoomExist(mRoom.getRoomId())) {
            // pop to the home activity
            Intent intent = new Intent(VectorRoomDetailsActivity.this, VectorHomeActivity.class);
            intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
                    | android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP);
            VectorRoomDetailsActivity.this.startActivity(intent);
            return;
        }//  w w w . j  a v a2s .c  o  m

        // listen for room leave event
        mRoom.addEventListener(mEventListener);

        // start the file search if the selected tab is the file one
        startFileSearch();
    }
}

From source file:im.vector.notifications.NotificationUtils.java

/**
 * Build an incoming call notification.//from   w w w .  j a  v  a  2s  .  co  m
 * This notification starts the VectorHomeActivity which is in charge of centralizing the incoming call flow.
 *
 * @param context  the context.
 * @param roomName the room name in which the call is pending.
 * @param matrixId the matrix id
 * @param callId   the call id.
 * @return the call notification.
 */
@SuppressLint("NewApi")
public static Notification buildIncomingCallNotification(Context context, String roomName, String matrixId,
        String callId) {
    addNotificationChannels(context);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CALL_NOTIFICATION_CHANNEL_ID);
    builder.setWhen(System.currentTimeMillis());

    builder.setContentTitle(roomName);
    builder.setContentText(context.getString(R.string.incoming_call));
    builder.setSmallIcon(R.drawable.incoming_call_notification_transparent);

    // Display the incoming call notification on the lock screen
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.setPriority(NotificationCompat.PRIORITY_MAX);
    }

    // clear the activity stack to home activity
    Intent intent = new Intent(context, VectorHomeActivity.class);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(VectorHomeActivity.EXTRA_CALL_SESSION_ID, matrixId);
    intent.putExtra(VectorHomeActivity.EXTRA_CALL_ID, callId);

    // Recreate the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorHomeActivity.class)
            .addNextIntent(intent);

    // android 4.3 issue
    // use a generator for the private requestCode.
    // When using 0, the intent is not created/launched when the user taps on the notification.
    //
    PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    builder.setLights(Color.GREEN, 500, 500);

    return builder.build();
}

From source file:kr.co.bettersoft.checkmileage.activities.GCMIntentService.java

/**
 * generateNotification/*from   w  w  w.j  ava 2s  .  c  om*/
 * Issues a notification to inform the user that server has sent a message.
 * @param context
 * @param message
 * @return
 */
private void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_stat_gcm;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when); // sdf
    String title = context.getString(R.string.app_name);
    String mileageUpdateStr = context.getString(R.string.mileage_noti);
    Intent notificationIntent;
    /*
     * MILEAGE :  ? ??  ? ???.
     * MARKETING : ?? ?    ?.
     * Check Mileage     ?. : test ..
     * 
     * <string name="gcm_new_msgkkk"> </string>
     */
    String new_msg = " ";

    if (message.equals(new_msg)) {
        Log.d(TAG, "new msg - test");
        notificationIntent = new Intent(context, DummyActivity.class);
        //            notificationIntent.putExtra("RunMode", "TEST");                  // ?? ? . ?? .. ?   ..
        notificationIntent.putExtra("RunMode", "MILEAGE"); //

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);

        //        }else if(message.contains("MILEAGE")){
        //        }else if(message.contains(mileageUpdateStr)){         // ?? ?. ()
    } else if (message.equals(mileageUpdateStr)) { // ?? ?. ().
        Log.d(TAG, "update mileage");
        MyMileagePageActivity.searched = false;
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ?..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MILEAGE");

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else if (message.equals("MARKETING")) {
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", "New Event");
        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    } else { //  ?.
        Log.d(TAG, "noti event push");
        //           notificationIntent = new Intent(context, MainActivity.class);      // ? ?  ? ?  ..
        notificationIntent = new Intent(context, DummyActivity.class);
        notificationIntent.putExtra("RunMode", "MARKETING");
        notificationIntent.putExtra("MESSAGE", message);

        // set intent so it does not start a new activity
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK 
        //                    | Intent.FLAG_ACTIVITY_CLEAR_TOP 
        //                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, title, message, intent);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, notification);
    }
}

From source file:com.marianhello.bgloc.LocationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    log.info("Received start startId: {} intent: {}", startId, intent);

    if (provider != null) {
        provider.onDestroy();/*from w w w. ja  v  a2  s. com*/
    }

    if (intent == null) {
        //service has been probably restarted so we need to load config from db
        ConfigurationDAO dao = DAOFactory.createConfigurationDAO(this);
        try {
            config = dao.retrieveConfiguration();
        } catch (JSONException e) {
            log.error("Config exception: {}", e.getMessage());
            config = new Config(); //using default config
        }
    } else {
        if (intent.hasExtra("config")) {
            config = intent.getParcelableExtra("config");
        } else {
            config = new Config(); //using default config
        }
    }

    log.debug("Will start service with: {}", config.toString());

    LocationProviderFactory spf = new LocationProviderFactory(this);
    provider = spf.getInstance(config.getLocationProvider());

    if (config.getStartForeground()) {
        // Build a Notification required for running service in foreground.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(config.getNotificationTitle());
        builder.setContentText(config.getNotificationText());
        if (config.getSmallNotificationIcon() != null) {
            builder.setSmallIcon(getDrawableResource(config.getSmallNotificationIcon()));
        } else {
            builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
        }
        if (config.getLargeNotificationIcon() != null) {
            builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(),
                    getDrawableResource(config.getLargeNotificationIcon())));
        }
        if (config.getNotificationIconColor() != null) {
            builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor()));
        }

        // Add an onclick handler to the notification
        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);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        builder.setContentIntent(contentIntent);

        Notification notification = builder.build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
                | Notification.FLAG_NO_CLEAR;
        startForeground(startId, notification);
    }

    provider.startRecording();

    //We want this service to continue running until it is explicitly stopped
    return START_STICKY;
}

From source file:com.orange.oidc.secproxy_service.HttpOpenidConnect.java

public boolean getTokens(Context ctx, String id, String login) {

    if (mOcp == null)
        return false;

    try {// w w  w  .j  a  v a  2 s.  com

        String requestObject = null;
        String authorization_endpoint = null;
        try {

            // retrieve openid config
            JSONObject json = getHttpJSON(mOcp.m_server_url + openIdConfigurationUrl);
            if (json == null) {
                Logd(TAG, "could not get openid-configuration on server : " + mOcp.m_server_url);
                return false;
            }

            // get authorization end_point
            authorization_endpoint = json.optString("authorization_endpoint");

            Logd(TAG, "authorization_endpoint : " + authorization_endpoint);

            // TAZTAG : no use to define request object if key jwt is not used ?
            if (mUsePrivateKeyJWT) {
                // get jwks_uri of the server
                String jwks_uri = json.optString("jwks_uri");
                if (jwks_uri == null || jwks_uri.length() < 1) {
                    Logd(TAG, "could not get jwks_uri from openid-configuration on server : "
                            + mOcp.m_server_url);
                    return false;
                }
                Logd(TAG, "jwks_uri : " + jwks_uri);

                // get jwks
                String jwks = getHttpString(jwks_uri);
                if (jwks == null || jwks.length() < 1) {
                    Logd(TAG, "could not get jwks_uri content from : " + jwks_uri);
                    return false;
                }
                Logd(TAG, "jwks : " + jwks);

                // extract public key
                PublicKey serverPubKey = KryptoUtils.pubKeyFromJwk(jwks);
                if (serverPubKey == null) {
                    Logd(TAG, "could not extract public key from jwk : " + jwks);
                    return false;
                }

                // get oidc request object
                requestObject = secureProxy.getOidcRequestObject(mOcp.m_server_url, mOcp.m_client_id,
                        mOcp.m_scope, serverPubKey);
                Logd(TAG, "secureStorage requestObject : " + requestObject);
            }

        } catch (Exception ee) {
            // error generating request object
            ee.printStackTrace();
            return false;
        }

        // build post parameters
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
        nameValuePairs.add(new BasicNameValuePair("redirect_uri", mOcp.m_redirect_uri));
        nameValuePairs.add(new BasicNameValuePair("response_type", "code"));
        nameValuePairs.add(new BasicNameValuePair("scope", mOcp.m_scope));

        nameValuePairs.add(new BasicNameValuePair("client_id", secureProxy.getClientId()));

        //         nameValuePairs.add(new BasicNameValuePair("nonce",         mOcp.m_nonce));
        nameValuePairs.add(new BasicNameValuePair("nonce", "1234567890"));
        if (!isEmpty(requestObject)) {
            nameValuePairs.add(new BasicNameValuePair("request", requestObject));
        }
        nameValuePairs.add(new BasicNameValuePair("prompt", "consent"));

        // get URL encoded string from list of key value pairs
        String postParams = getQuery(nameValuePairs);

        Log.d(TAG, "get URL encoded string from list of key value pairs : " + postParams);

        // launch webview

        // init intent
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setClass(ctx, WebViewActivity.class);

        // prepare request parameters
        intent.putExtra("id", id);

        intent.putExtra("server_url", authorization_endpoint);
        intent.putExtra("redirect_uri", mOcp.m_redirect_uri);
        intent.putExtra("client_id", mOcp.m_client_id);
        if (login != null)
            intent.putExtra("login", login);

        intent.putExtra("postParams", postParams);

        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_NO_ANIMATION);

        // display webview
        ctx.startActivity(intent);

    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java

private PendingIntent createContentIntent(Class activityClass) {
    Intent openUI = new Intent(mService, activityClass);
    openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.digi.android.wva.VehicleInfoService.java

/**
 * Depending on if the service is currently set as 'connected'
 * (check value of {@code isConnected} boolean), either call
 * {@link #startForeground(int, Notification)} to put up the
 * "service is running" notification, or call
 * {@link #stopForeground(boolean) stopForeground(true)} to remove the
 * notification (because the service isn't listening).
  */*from w w w  .  j  a v  a  2 s  .c o  m*/
  * <p>This method is protected, rather than private, due to a bug between JaCoCo and
  * the Android build tools which causes the instrumented bytecode to be invalid when this
  * method is private:
  * http://stackoverflow.com/questions/17603192/dalvik-transformation-using-wrong-invoke-opcode
  * </p>
 */
protected void showNotificationIfRunning() {
    // First, c
    WvaApplication app = (WvaApplication) getApplication();
    if (app != null && app.isTesting())
        return;

    if (isConnected) {
        NotificationCompat.Builder builder;
        builder = new NotificationCompat.Builder(getApplicationContext());
        PendingIntent contentIntent;
        Intent intent = new Intent(VehicleInfoService.this, DashboardActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        contentIntent = PendingIntent.getActivity(VehicleInfoService.this, 0, intent, 0);
        builder.setContentTitle("Digi WVA Service")
                .setContentText("Connected to " + (TextUtils.isEmpty(connectIp) ? "(null)" : connectIp))
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
                .setSmallIcon(R.drawable.notif_small).setOngoing(true).setContentIntent(contentIntent);

        startForeground(NOTIF_ID, builder.build());
    } else {
        try {
            stopForeground(true);
        } catch (Exception e) {
            // Might happen if startForeground not called before
            e.printStackTrace();
        }
    }
}

From source file:com.hpush.app.activities.MainActivity.java

/**
 * Show single instance of {@link com.hpush.app.activities.MainActivity}
 *
 * @param cxt/*from  w w w  . j ava2  s  .com*/
 *       {@link android.content.Context}.
 */
public static void showInstance(Context cxt) {
    Intent intent = new Intent(cxt, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    cxt.startActivity(intent);
}