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.orange.oidc.tim.service.HttpOpenidConnect.java

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

    if (mOcp == null)
        return false;

    try {/*  ww w .jav  a  2  s  . c  o  m*/

        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");

            if (useTim) {
                // 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;
                }

                // 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;
                }

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

                // get tim request object
                requestObject = secureStorage.getTimRequestObject(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));
        if (useTim)
            nameValuePairs.add(new BasicNameValuePair("client_id", secureStorage.getClientId()));
        else
            nameValuePairs.add(new BasicNameValuePair("client_id", mOcp.m_client_id));
        nameValuePairs.add(new BasicNameValuePair("nonce", mOcp.m_nonce));
        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);

        // 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);

        if (useTim) {
            intent.putExtra("use_tim", true);
        } else {
            intent.putExtra("client_secret", mOcp.m_client_secret);
        }
        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.frostwire.android.gui.fragments.SlideMenuFragment.java

private void launchPlayerActivity() {
    if (getActivity() == null) {
        return;//w  w w .j a  v  a 2 s.co  m
    }

    if (getActivity() instanceof MainActivity) {
        ((MainActivity) getActivity()).showContent();
    }

    if (Engine.instance().getMediaPlayer().getCurrentFD() != null) {
        Intent i = new Intent(getActivity(), MediaPlayerActivity.class);
        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        getActivity().startActivity(i);
    }
}

From source file:com.anhuioss.crowdroid.activity.MoreFunctionActivity.java

@Override
public void onClick(View view) {
    // TODO Auto-generated method stub
    switch (view.getId()) {
    case R.id.head_back: {
        finish();/*from  w w w  .j  a va  2  s . c  o  m*/
        break;
    }
    case R.id.head_refresh: {
        Intent comment = new Intent(MoreFunctionActivity.this, HomeTimelineActivity.class);
        startActivity(comment);
        break;
    }
    case R.id.account_manage: {
        Intent intent = new Intent(MoreFunctionActivity.this, AccountManageActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.themes_setting: {
        Intent intent = new Intent(MoreFunctionActivity.this, ThemeSettingActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.skim: {
        Intent intent = new Intent(MoreFunctionActivity.this, BrowseModeActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.weibo_setting: {
        Intent intent = new Intent(MoreFunctionActivity.this, WeiBoSettingActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.setting: {
        Intent intent = new Intent(MoreFunctionActivity.this, PersonalSettingActivity.class);
        startActivity(intent);
        break;
    }
    case R.id.license: {
        LicenseDialog lic = new LicenseDialog(this);
        lic.show();
        break;
    }
    case R.id.about: {
        Uri uri = null;
        String language = this.getApplicationContext().getResources().getConfiguration().locale.getLanguage();
        if (language != null && language.equals("zh")) {
            uri = Uri.parse("http://www.anhuioss.com/cn/crowdroid");
        } else if (language != null && language.equals("ja")) {
            uri = Uri.parse("http://www.anhuioss.com/crowdroid");
        } else {
            uri = Uri.parse("http://www.anhuioss.com/en/crowdroid");
        }
        Intent i = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(i);
        break;
    }
    case R.id.office_weibo: {
        Intent intent = new Intent(MoreFunctionActivity.this, ProfileActivity.class);
        Bundle bundle = new Bundle();
        if (statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_CROWDROID_FOR_BUSINESS)) {
            bundle.putString("name", "nakao");
            bundle.putString("uid", "11");
        } else if (statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_TWITTER)
                || statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_TWITTER_PROXY)) {
            String language = this.getApplicationContext().getResources().getConfiguration().locale
                    .getLanguage();
            if (language != null && language.equals("zh")) {
                bundle.putString("name", "anhuioss_cn");
            } else if (language != null && language.equals("ja")) {
                bundle.putString("name", "AnhuiOSS");
            } else {
                bundle.putString("name", "AnhuiOSS_EN");

            }

        } else if (statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_SINA)
                || statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_TENCENT)
                || statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_SOHU)) {
            bundle.putString("name", "???");
            bundle.putString("user_name", "anhuioss");
        } else {
            bundle.putString("name", "???");
            bundle.putString("user_name", "???");
            bundle.putString("uid", "324411430");

        }
        // bundle.putString("name", "");
        // bundle.putString("user_name", "");
        // bundle.putString("uid","");
        intent.putExtras(bundle);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);
        break;
    }
    case R.id.check_update: {
        new DownloadUpdateDialog(this).show();
        break;
    }
    case R.id.logout: {
        confirmLogoutDialog();
        break;
    }
    case R.id.feedback: {
        if (statusData.getCurrentService().equals(IGeneral.SERVICE_NAME_RENREN)) {
            Intent intent = new Intent(MoreFunctionActivity.this, CommentActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("message_id", "478083032");
            bundle.putString("message", "");
            bundle.putString("user_id", "324411430");
            bundle.putString("feed_type", "20");
            bundle.putString("feedback", "");
            intent.putExtras(bundle);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        } else {
            Intent intent = new Intent(MoreFunctionActivity.this, SendMessageActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("feedback", "FeedBack");
            intent.putExtras(bundle);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        }

        break;
    }
    default:
        break;
    }
}

From source file:kashmirr.social.service.NotificationService.java

public void sendGroupRequestNotification(Context context, String requesterName, String requestedGroup,
        String requestId) {//from  w w w. j a  v  a 2s. co m

    NotificationManager notificationManagerCompat = (NotificationManager) context
            .getSystemService(NOTIFICATION_SERVICE);

    Intent requestsViewIntent = new Intent(context, RequestsView.class);
    requestsViewIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent requestsViewPending = PendingIntent.getActivity(context, Integer.valueOf(requestId),
            requestsViewIntent, 0);
    android.support.v7.app.NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(
            context);
    builder.setSmallIcon(R.drawable.ic_account_switch_white_24dp);
    builder.setAutoCancel(true);

    builder.setContentTitle(
            requesterName + " " + getString(R.string.requestedText) + " " + "'" + requestedGroup + "'");
    builder.setContentText(getString(R.string.requestedTextBody));
    builder.setGroup(GROUP_KEY_MESSAGES);
    builder.setDefaults(android.app.Notification.DEFAULT_ALL);
    builder.setContentIntent(requestsViewPending);
    builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.requestedTextBody)));
    builder.setShowWhen(true);
    android.app.Notification notification = builder.build();
    notificationManagerCompat.notify(Integer.valueOf(requestId), notification);
}

From source file:com.shivshankar.MyFirebaseMessagingService.java

private void sendNotification(String strTitle, String strMsg) {
    Log.d("TAGRK", "Preparing to send notification...: " + strTitle + "  Msg: " + strMsg);
    NotificationManager mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent;/*w ww.j a va  2 s.c om*/
    if (AppPreferences.getPrefs().getBoolean(commonVariables.KEY_IS_SELLER, false))
        intent = new Intent(this, MainActivitySeller.class);
    else
        intent = new Intent(this, MainActivityBuyer.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    int requestID = (int) System.currentTimeMillis();
    PendingIntent contentIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this, requestID, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setContentTitle(strTitle)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(strMsg)).setContentText(strMsg)
            .setPriority(NotificationCompat.PRIORITY_MAX).setWhen(0).setVibrate(new long[] { 100, 100, 0, 0 });

    mBuilder.setSmallIcon(R.drawable.ic_noti_fcm);
    try {
        Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
        r.play();
    } catch (Exception e) {
        e.printStackTrace();
    }

    mBuilder.setAutoCancel(true);
    if (!strMsg.contains("Your OTP is"))
        mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID++, mBuilder.build());
    Log.d("TAGRK", "Notification sent successfully.");
}

From source file:crea.wallet.lite.service.CreativeCoinService.java

private void notifyCoinsReceived(Sha256Hash hash) {
    if (!Configuration.getInstance().isNotificationsEnabled()) {
        return;/*ww  w  .ja v a 2 s .co  m*/
    }

    int notificationCount = transactionsReceived.size();
    if (notificationCount == 1) {
        nm.cancel(NOTIFICATION_ID_COINS_RECEIVED);
    }

    notificationAccumulatedAmount = Coin.ZERO;
    for (Coin c : transactionsReceived.values()) {
        notificationAccumulatedAmount = notificationAccumulatedAmount.add(c);
    }

    Coin coin = Coin.valueOf(notificationAccumulatedAmount.getValue());
    String msg;
    Intent intent;

    msg = getString(R.string.notif_accumulated_amount, coin.toFriendlyString(), notificationCount);
    intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    intent.putExtra(TransactionActivity.TRANSACTION_ID, hash.toString());

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    String title = getString(R.string.notif_cash_in_title, coin.toFriendlyString());
    final NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
    notification.setSmallIcon(R.mipmap.ic_notification);
    notification.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
    notification.setColor(getResources().getColor(R.color.colorPrimary));
    notification.setContentText(msg);
    notification.setContentTitle(title);
    notification.setWhen(System.currentTimeMillis());
    notification.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notification.setContentIntent(pendingIntent);
    Notification notif = notification.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notif);
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +/*from   ww w  .j  a  v a2s .  c o m*/
 * @throws JSONException 
 */
@SuppressLint("InlinedApi")
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setTicker(json.getString("title"))
            .setContentTitle(json.getString("message")).setContentIntent(contentIntent);

    String message = json.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());
}

From source file:com.mattprecious.notisync.service.PrimaryService.java

private Notification buildRunningNotification(boolean nullIfNoChange) {
    Bundle notificationBundle = new Bundle();

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setPriority(NotificationCompat.PRIORITY_MIN);
    builder.setSmallIcon(R.drawable.ic_stat_logo);
    builder.setContentTitle(getString(R.string.app_name));

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    builder.setContentIntent(pendingIntent);

    String contentText = null;/* w w w .  j  av  a2s.c  o  m*/
    Set<String> connectedNames = Sets.newHashSet();

    if (bluetoothAdapter.isEnabled()) {
        synchronized (bluetoothServices) {
            for (String address : bluetoothServices.keySet()) {
                BluetoothService service = bluetoothServices.get(address);
                if (service != null && service.getState() == BluetoothService.STATE_CONNECTED) {
                    BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
                    connectedNames.add(device.getName());
                }
            }
        }

        if (connectedNames.size() != Preferences.getDevices(this).size()) {
            PendingIntent reconnectIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_RECONNECT),
                    0);
            builder.addAction(R.drawable.ic_action_refresh, getString(R.string.noti_action_connect),
                    reconnectIntent);

            notificationBundle.putBoolean("connect_action", true);
        }

        if (connectedNames.size() > 0) {
            contentText = getString(R.string.noti_connected_to, notificationJoiner.join(connectedNames));
        } else {
            contentText = getString(R.string.noti_not_connected);
        }
    } else {
        contentText = getString(R.string.noti_bt_not_enabled);

        PendingIntent bluetoothIntent = PendingIntent.getActivity(this, 0,
                new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), 0);
        builder.addAction(R.drawable.ic_action_bluetooth, getString(R.string.noti_action_enable_bt),
                bluetoothIntent);

        notificationBundle.putBoolean("bt_enable_action", true);
    }

    builder.setContentText(contentText);
    notificationBundle.putString("text", contentText);

    if (nullIfNoChange && bundleEquals(notificationBundle, lastNotificationBundle)) {
        return null;
    }

    lastNotificationBundle = notificationBundle;

    return builder.build();
}

From source file:mobilelecture.cdp12_app.RecoRangingActivity.java

@Override
protected void onDestroy() {

    Intent intent_getType = getIntent();
    String activity_TYPE = intent_getType.getStringExtra("TYPE");

    Intent intent_out_location;//from  w  w  w .  j  ava2  s.c  o  m

    Log.i("", "activity_TYPE : " + activity_TYPE);
    if (activity_TYPE != null && activity_TYPE.equals("0")) {
        //if (activity_TYPE.equalsIgnoreCase("0")) {
        intent_out_location = new Intent(getApplicationContext(), MapViewActivity.class);
        intent_out_location.putExtra("current_location_ID", return_location_ID);
        intent_out_location.putExtra("current_location_LOC", temp_location + "");
        Log.i("RECORangingActivity", "" + return_location_ID + "  " + temp_location);
        intent_out_location.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent_out_location);
    } else {
        Intent intent_out_inform = getIntent();
        String menuname = intent_out_inform.getStringExtra("GoodsName");
        String cornername = intent_out_inform.getStringExtra("ConerName");

        Log.i("RECORangingActivity", "menu + coner : " + menuname + " " + cornername);

        intent_out_location = new Intent(getApplicationContext(), GoodsMapSearch.class);
        intent_out_location.putExtra("current_location_ID", return_location_ID);
        intent_out_location.putExtra("current_location_LOC", temp_location + "");
        intent_out_location.putExtra("GoodsName", menuname);
        intent_out_location.putExtra("ConerName", cornername);

        intent_out_location.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent_out_location);
        //setResult(RESULT_OK, intent_out_inform);
    }

    super.onDestroy();
    this.stop(mRegions);
    this.unbind();
}

From source file:com.scooter1556.sms.android.manager.MediaNotificationManager.java

private PendingIntent createContentIntent(MediaDescriptionCompat description) {
    Intent intent = new Intent(mediaService, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(HomeActivity.EXTRA_START_FULLSCREEN, true);

    if (description != null) {
        intent.putExtra(HomeActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, description);
    }/*www  . j  a v a2  s . co m*/

    return PendingIntent.getActivity(mediaService, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}