Example usage for android.content Intent FLAG_ACTIVITY_REORDER_TO_FRONT

List of usage examples for android.content Intent FLAG_ACTIVITY_REORDER_TO_FRONT

Introduction

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

Prototype

int FLAG_ACTIVITY_REORDER_TO_FRONT

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

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause the launched activity to be brought to the front of its task's history stack if it is already running.

Usage

From source file:co.tinode.tindroid.ContactsFragment.java

private void handleItemClick(final ContactsAdapter.ViewHolder tag) {
    boolean done = false;
    if (mPhEmImData != null) {
        Utils.ContactHolder holder = mPhEmImData.get(tag.contact_id);
        if (holder != null) {
            String address = holder.getIm();
            if (address != null) {
                Intent it = new Intent(getActivity(), MessageActivity.class);
                it.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                it.putExtra("topic", address);
                startActivity(it);//w  ww .  j  a va  2 s  .c  o m
                done = true;
            }

            if (!done && ((address = holder.getPhone()) != null)) {
                // Send an SMS with an invitation
                Uri uri = Uri.fromParts("smsto", address, null);
                Intent it = new Intent(Intent.ACTION_SENDTO, uri);
                it.putExtra("sms_body", getString(R.string.tinode_invite_body));
                startActivity(it);
                done = true;
            }
            if (!done && ((address = holder.getEmail()) != null)) {
                Uri uri = Uri.fromParts("mailto", address, null);
                Intent it = new Intent(Intent.ACTION_SENDTO, uri);
                it.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.tinode_invite_subject));
                it.putExtra(Intent.EXTRA_TEXT, getString(R.string.tinode_invite_body));
                startActivity(it);
                done = true;
            }
        }
    }

    if (!done) {
        Toast.makeText(getContext(), R.string.failed_to_invite, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.bt.download.android.gui.activities.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {

    if (isShutdown(intent)) {
        return;/*from  www  .ja  v a 2  s  . c  o  m*/
    }

    String action = intent.getAction();
    //onResumeFragments();

    if (action != null && action.equals(Constants.ACTION_SHOW_TRANSFERS)) {
        if (Ads.isLoaded(Fetcher.AdFormat.interstitial, Constants.TAG_INTERSTITIAL_WIDGET)) {
            Ads.showAppWidget(this, null, Constants.TAG_INTERSTITIAL_WIDGET, Ads.ShowMode.FULL_SCREEN);
        }

        controller.showTransfers(TransferStatus.ALL);
    } else if (action != null && action.equals(Constants.ACTION_OPEN_TORRENT_URL)) {
        //Open a Torrent from a URL or from a local file :), say from Astro File Manager.
        /**
         * TODO: Ask @aldenml the best way to plug in NewTransferDialog.
         * I've refactored this dialog so that it is forced (no matter if the setting
         * to not show it again has been used) and when that happens the checkbox is hidden.
         * 
         * However that dialog requires some data about the download, data which is not
         * obtained until we have instantiated the Torrent object.
         * 
         * I'm thinking that we can either:
         * a) Pass a parameter to the transfer manager, but this would probably
         * not be cool since the transfer manager (I think) should work independently from
         * the UI thread.
         * 
         * b) Pass a "listener" to the transfer manager, once the transfer manager has the torrent
         * it can notify us and wait for the user to decide wether or not to continue with the transfer
         * 
         * c) Forget about showing that dialog, and just start the download, the user can cancel it.
         */

        //Show me the transfer tab
        Intent i = new Intent(this, MainActivity.class);
        i.setAction(Constants.ACTION_SHOW_TRANSFERS);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivity(i);

        //go!
        TransferManager.instance().downloadTorrent(intent.getDataString());
    }
    // When another application wants to "Share" a file and has chosen FrostWire to do so.
    // We make the file "Shared" so it's visible for other FrostWire devices on the local network.
    else if (action != null
            && (action.equals(Intent.ACTION_SEND) || action.equals(Intent.ACTION_SEND_MULTIPLE))) {
        controller.handleSendAction(intent);
    }

    if (intent.hasExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION)) {
        controller.showTransfers(TransferStatus.COMPLETED);
        TransferManager.instance().clearDownloadsToReview();
        try {
            ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                    .cancel(Constants.NOTIFICATION_DOWNLOAD_TRANSFER_FINISHED);
            Bundle extras = intent.getExtras();
            if (extras.containsKey(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH)) {
                File file = new File(extras.getString(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH));
                if (file.isFile()) {
                    UIUtils.openFile(this, file.getAbsoluteFile());
                }
            }
        } catch (Throwable e) {
            LOG.warn("Error handling download complete notification", e);
        }
    }
}

From source file:ti.modules.titanium.audio.streamer.NotificationHelper.java

/**
 * Open to the now playing screen/*ww w  .j av a 2 s .  co  m*/
 */
private PendingIntent getPendingIntent() {
    TiApplication app = TiApplication.getInstance();
    Intent i = app.getPackageManager().getLaunchIntentForPackage(app.getPackageName());
    i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setAction(Intent.ACTION_MAIN);
    PendingIntent pendingIntent = PendingIntent.getActivity(app, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
}

From source file:securityantennas.viwer.android.mogaworks.securityantenna.FeedListFragment.java

/**
 * Load an article in the default browser when selected by the user.
 *//*from w  w  w  . j  a v  a 2 s. c o m*/
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);

    // Get the item at the selected position, in the form of a Cursor.
    Cursor c = (Cursor) mAdapter.getItem(position);
    // Get the link to the article represented by the item.
    String articleUrlString = c.getString(COLUMN_URL_STRING);
    String articleTitleString = c.getString(COLUMN_TITLE);
    if (articleUrlString == null) {
        Log.e(TAG, "Attempt to launch entry with null link");
        return;
    }

    Log.i(TAG, "Opening URL: " + articleUrlString);

    Intent intent = new Intent(getActivity().getApplicationContext(), WebActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

    intent.putExtra("title", articleTitleString);
    intent.putExtra("url", articleUrlString.replace("www.jpcert.or.jp", "www.jpcert.or.jp/m"));
    startActivity(intent);
}

From source file:de.vanita5.twittnuker.fragment.support.AccountsDashboardFragment.java

@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    final ListAdapter adapter = mAdapter.getAdapter(position);
    final Object item = mAdapter.getItem(position);
    if (adapter instanceof AccountOptionsAdapter) {
        final ParcelableAccount account = mAccountsAdapter.getSelectedAccount();
        if (account == null || !(item instanceof OptionItem))
            return;
        final OptionItem option = (OptionItem) item;
        switch (option.id) {
        case MENU_SEARCH: {
            //                    final FragmentActivity a = getActivity();
            //                    if (a instanceof HomeActivity) {
            //                        ((HomeActivity) a).openSearchView(account);
            //                    } else {
            //                        getActivity().onSearchRequested();
            //                    }
            final Intent intent = new Intent(getActivity(), QuickSearchBarActivity.class);
            intent.putExtra(EXTRA_ACCOUNT_ID, account.account_id);
            startActivity(intent);//from ww  w. j  a  v  a 2s. co m
            closeAccountsDrawer();
            break;
        }
        case MENU_COMPOSE: {
            final Intent composeIntent = new Intent(INTENT_ACTION_COMPOSE);
            composeIntent.setClass(getActivity(), ComposeActivity.class);
            composeIntent.putExtra(EXTRA_ACCOUNT_IDS, new long[] { account.account_id });
            startActivity(composeIntent);
            break;
        }
        case MENU_FAVORITES: {
            openUserFavorites(getActivity(), account.account_id, account.account_id, account.screen_name);
            break;
        }
        case MENU_LISTS: {
            openUserLists(getActivity(), account.account_id, account.account_id, account.screen_name);
            break;
        }
        case MENU_EDIT: {
            final Bundle bundle = new Bundle();
            bundle.putLong(EXTRA_ACCOUNT_ID, account.account_id);
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), UserProfileEditorActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
            break;
        }
        }
    } else if (adapter instanceof AppMenuAdapter) {
        if (!(item instanceof OptionItem))
            return;
        final OptionItem option = (OptionItem) item;
        switch (option.id) {
        case MENU_ACCOUNTS: {
            final Intent intent = new Intent(getActivity(), AccountsManagerActivity.class);
            startActivity(intent);
            break;
        }
        case MENU_DRAFTS: {
            final Intent intent = new Intent(INTENT_ACTION_DRAFTS);
            intent.setClass(getActivity(), DraftsActivity.class);
            startActivity(intent);
            break;
        }
        case MENU_FILTERS: {
            final Intent intent = new Intent(getActivity(), FiltersActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(intent);
            break;
        }
        case MENU_SETTINGS: {
            final Intent intent = new Intent(getActivity(), SettingsActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivityForResult(intent, REQUEST_SETTINGS);
            break;
        }
        }
        closeAccountsDrawer();
    }
}

From source file:de.lespace.apprtc.ConnectActivity.java

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

    setContentView(R.layout.activity_connect);
    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    keyprefFrom = getString(R.string.pref_from_key);
    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefAecDump = getString(R.string.pref_aecdump_key);
    keyprefOpenSLES = getString(R.string.pref_opensles_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefTracing = getString(R.string.pref_tracing_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefRoom = getString(R.string.pref_room_key);
    keyprefRoomList = getString(R.string.pref_room_list_key);
    from = sharedPref.getString(keyprefFrom, getString(R.string.pref_from_default));
    //    String roomUrl = sharedPref.getString(
    //            keyprefRoomServerUrl, getString(R.string.pref_room_server_url_default));

    // Video call enabled flag.
    boolean videoCallEnabled = sharedPref.getBoolean(keyprefVideoCallEnabled,
            Boolean.valueOf(getString(R.string.pref_videocall_default)));

    // Get default codecs.
    String videoCodec = sharedPref.getString(keyprefVideoCodec, getString(R.string.pref_videocodec_default));
    String audioCodec = sharedPref.getString(keyprefAudioCodec, getString(R.string.pref_audiocodec_default));

    // Check HW codec flag.
    boolean hwCodec = sharedPref.getBoolean(keyprefHwCodecAcceleration,
            Boolean.valueOf(getString(R.string.pref_hwcodec_default)));

    // Check Capture to texture.
    boolean captureToTexture = sharedPref.getBoolean(keyprefCaptureToTexture,
            Boolean.valueOf(getString(R.string.pref_capturetotexture_default)));

    // Check Disable Audio Processing flag.
    boolean noAudioProcessing = sharedPref.getBoolean(keyprefNoAudioProcessingPipeline,
            Boolean.valueOf(getString(R.string.pref_noaudioprocessing_default)));

    // Check Disable Audio Processing flag.
    boolean aecDump = sharedPref.getBoolean(keyprefAecDump,
            Boolean.valueOf(getString(R.string.pref_aecdump_default)));

    // Check OpenSL ES enabled flag.
    boolean useOpenSLES = sharedPref.getBoolean(keyprefOpenSLES,
            Boolean.valueOf(getString(R.string.pref_opensles_default)));

    // Check for mandatory permissions.
    int counter = 0;
    missingPermissions = new ArrayList();

    for (String permission : MANDATORY_PERMISSIONS) {
        if (checkCallingOrSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
            counter++;// w w  w.  ja  va  2  s .co  m
            missingPermissions.add(permission);
        }
    }
    requestPermission();
    // mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    gcmRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            if (sentToken) {
                logAndToast(getString(R.string.gcm_send_message));
                // mInformationTextView.setText(getString(R.string.gcm_send_message));
            } else {
                logAndToast(getString(R.string.gcm_send_message));
                // mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };

    //Bring Call2Front when
    bringToFrontBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            Intent intentStart = new Intent(getApplicationContext(), ConnectActivity.class);
            // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
            startActivity(intentStart);
            //  newFragment.show(transaction,"loading");

            //  showDialog();
        }
    };

    // Registering BroadcastReceiver
    registerGCMReceiver();
    registerBringToFrontReceiver();

    if (checkPlayServices()) {
        // Start IntentService to register this application with GCM.
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
    }
    // Get video resolution from settings.
    int videoWidth = 0;
    int videoHeight = 0;
    String resolution = sharedPref.getString(keyprefResolution, getString(R.string.pref_resolution_default));
    String[] dimensions = resolution.split("[ x]+");
    if (dimensions.length == 2) {
        try {
            videoWidth = Integer.parseInt(dimensions[0]);
            videoHeight = Integer.parseInt(dimensions[1]);
        } catch (NumberFormatException e) {
            videoWidth = 0;
            videoHeight = 0;
            Log.e(TAG, "Wrong video resolution setting: " + resolution);
        }
    }

    // Get camera fps from settings.
    int cameraFps = 0;
    String fps = sharedPref.getString(keyprefFps, getString(R.string.pref_fps_default));
    String[] fpsValues = fps.split("[ x]+");
    if (fpsValues.length == 2) {
        try {
            cameraFps = Integer.parseInt(fpsValues[0]);
        } catch (NumberFormatException e) {
            Log.e(TAG, "Wrong camera fps setting: " + fps);
        }
    }

    // Check capture quality slider flag.
    boolean captureQualitySlider = sharedPref.getBoolean(keyprefCaptureQualitySlider,
            Boolean.valueOf(getString(R.string.pref_capturequalityslider_default)));

    // Get video and audio start bitrate.
    int videoStartBitrate = 0;
    String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_default);
    String bitrateType = sharedPref.getString(keyprefVideoBitrateType, bitrateTypeDefault);
    if (!bitrateType.equals(bitrateTypeDefault)) {
        String bitrateValue = sharedPref.getString(keyprefVideoBitrateValue,
                getString(R.string.pref_startvideobitratevalue_default));
        videoStartBitrate = Integer.parseInt(bitrateValue);
    }
    int audioStartBitrate = 0;
    bitrateTypeDefault = getString(R.string.pref_startaudiobitrate_default);
    bitrateType = sharedPref.getString(keyprefAudioBitrateType, bitrateTypeDefault);
    if (!bitrateType.equals(bitrateTypeDefault)) {
        String bitrateValue = sharedPref.getString(keyprefAudioBitrateValue,
                getString(R.string.pref_startaudiobitratevalue_default));
        audioStartBitrate = Integer.parseInt(bitrateValue);
    }

    // Check statistics display option.
    boolean displayHud = sharedPref.getBoolean(keyprefDisplayHud,
            Boolean.valueOf(getString(R.string.pref_displayhud_default)));

    boolean tracing = sharedPref.getBoolean(keyprefTracing,
            Boolean.valueOf(getString(R.string.pref_tracing_default)));

    Log.d(TAG, "Connecting from " + from + " at URL " + Configs.ROOM_URL);

    if (validateUrl(Configs.ROOM_URL)) {
        Uri uri = Uri.parse(Configs.ROOM_URL);
        intent = new Intent(this, ConnectActivity.class);
        intent.setData(uri);
        intent.putExtra(CallActivity.EXTRA_VIDEO_CALL, videoCallEnabled);
        intent.putExtra(CallActivity.EXTRA_VIDEO_WIDTH, videoWidth);
        intent.putExtra(CallActivity.EXTRA_VIDEO_HEIGHT, videoHeight);
        intent.putExtra(CallActivity.EXTRA_VIDEO_FPS, cameraFps);
        intent.putExtra(CallActivity.EXTRA_VIDEO_CAPTUREQUALITYSLIDER_ENABLED, captureQualitySlider);
        intent.putExtra(CallActivity.EXTRA_VIDEO_BITRATE, videoStartBitrate);
        intent.putExtra(CallActivity.EXTRA_VIDEOCODEC, videoCodec);
        intent.putExtra(CallActivity.EXTRA_HWCODEC_ENABLED, hwCodec);
        intent.putExtra(CallActivity.EXTRA_CAPTURETOTEXTURE_ENABLED, captureToTexture);
        intent.putExtra(CallActivity.EXTRA_NOAUDIOPROCESSING_ENABLED, noAudioProcessing);
        intent.putExtra(CallActivity.EXTRA_AECDUMP_ENABLED, aecDump);
        intent.putExtra(CallActivity.EXTRA_OPENSLES_ENABLED, useOpenSLES);
        intent.putExtra(CallActivity.EXTRA_AUDIO_BITRATE, audioStartBitrate);
        intent.putExtra(CallActivity.EXTRA_AUDIOCODEC, audioCodec);
        intent.putExtra(CallActivity.EXTRA_DISPLAY_HUD, displayHud);
        intent.putExtra(CallActivity.EXTRA_TRACING, tracing);
        intent.putExtra(CallActivity.EXTRA_CMDLINE, commandLineRun);
        intent.putExtra(CallActivity.EXTRA_RUNTIME, runTimeMs);
    }

    roomListView = (ListView) findViewById(R.id.room_listview);
    roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    connectButton = (ImageButton) findViewById(R.id.connect_button);
    connectButton.setOnClickListener(connectListener);

    // If an implicit VIEW intent is launching the app, go directly to that URL.
    //final Intent intent = getIntent();
    Uri wsurl = Uri.parse(Configs.ROOM_URL);
    //intent.getData();
    Log.d(TAG, "connecting to:" + wsurl.toString());
    if (wsurl == null) {
        logAndToast(getString(R.string.missing_wsurl));
        Log.e(TAG, "Didn't get any URL in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    if (from == null || from.length() == 0) {
        logAndToast(getString(R.string.missing_from));
        Log.e(TAG, "Incorrect from in intent!");
        setResult(RESULT_CANCELED);
        finish();
        return;
    }

    peerConnectionParameters = new PeerConnectionClient.PeerConnectionParameters(videoCallEnabled, tracing,
            videoWidth, videoHeight, cameraFps, videoStartBitrate, videoCodec, hwCodec, captureToTexture,
            audioStartBitrate, audioCodec, noAudioProcessing, aecDump, useOpenSLES);

    roomConnectionParameters = new AppRTCClient.RoomConnectionParameters(wsurl.toString(), from, false);

    Log.i(TAG, "creating appRtcClient with roomUri:" + wsurl.toString() + " from:" + from);
    // Create connection client and connection parameters.
    appRtcClient = new WebSocketRTCClient(this, new LooperExecutor());

    connectToWebsocket();
    // ATTENTION: This was auto-generated to implement the App Indexing API.
    // See https://g.co/AppIndexing/AndroidStudio for more information.
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}

From source file:nl.privacybarometer.privacyvandaag.service.FetcherService.java

@Override
public void onHandleIntent(Intent intent) {
    if (intent == null) { // No intent, we quit
        return;//w w w  .j a  va2 s. c o  m
    }

    boolean isFromAutoRefresh = intent.getBooleanExtra(Constants.FROM_AUTO_REFRESH, false);

    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(
            Context.CONNECTIVITY_SERVICE);
    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    // Connectivity issue, we quit
    if (networkInfo == null || networkInfo.getState() != NetworkInfo.State.CONNECTED) {
        if (ACTION_REFRESH_FEEDS.equals(intent.getAction()) && !isFromAutoRefresh) {
            // Display a toast in that case
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(FetcherService.this, R.string.network_error, Toast.LENGTH_SHORT).show();
                }
            });
        }
        return;
    }

    boolean skipFetch = isFromAutoRefresh && PrefUtils.getBoolean(PrefUtils.REFRESH_WIFI_ONLY, false)
            && networkInfo.getType() != ConnectivityManager.TYPE_WIFI;
    // We need to skip the fetching process, so we quit
    if (skipFetch) {
        return;
    }

    if (ACTION_MOBILIZE_FEEDS.equals(intent.getAction())) {
        mobilizeAllEntries();
        downloadAllImages();
    } else if (ACTION_DOWNLOAD_IMAGES.equals(intent.getAction())) {
        downloadAllImages();
    } else { // == Constants.ACTION_REFRESH_FEEDS
        PrefUtils.putBoolean(PrefUtils.IS_REFRESHING, true);

        if (isFromAutoRefresh) {
            PrefUtils.putLong(PrefUtils.LAST_SCHEDULED_REFRESH, SystemClock.elapsedRealtime());
        }

        /* ModPrivacyVandaag: De defaultwaarde voor het bewaren van artikelen is 30.
        Dus moet de defaultwaarde bij het ophalen ook die waarde hebben, om te voorkomen dat de
        voorkeuren (nog) niet goed ingesteld of gelezen worden.
        In onderstaande dus bij de getString "30" geplaatst. Origineel was "4"
         */
        long keepTime = Long.parseLong(PrefUtils.getString(PrefUtils.KEEP_TIME, "30")) * 86400000l;
        long keepDateBorderTime = keepTime > 0 ? System.currentTimeMillis() - keepTime : 0;

        deleteOldEntries(keepDateBorderTime);

        String feedId = intent.getStringExtra(Constants.FEED_ID);
        int newCount = (feedId == null ? refreshFeeds(keepDateBorderTime)
                : refreshFeed(feedId, keepDateBorderTime)); // number of new articles found after refresh all the feeds

        // notification for new articles.
        if (newCount > 0 && isFromAutoRefresh && PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_ENABLED, true)) {
            int mNotificationId = 2; // een willekeurige ID, want we doen er nu niks mee
            Intent notificationIntent = new Intent(FetcherService.this, HomeActivity.class);
            // Voorlopig doen we niets met aantallen, want wekt verwarring omdat aantal in de melding kan afwijken van totaal nieuw.
            newCount += PrefUtils.getInt(PrefUtils.NOTIFICATIONS_PREVIOUS_COUNT, 0); // Tel aantal van bestaande melding erbij op
            String text = getResources().getQuantityString(R.plurals.number_of_new_entries, newCount, newCount);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            PendingIntent contentIntent = PendingIntent.getActivity(FetcherService.this, mNotificationId,
                    notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(
                    MainApplication.getContext()) //
                            .setContentIntent(contentIntent) // Wat moet er gebeuren als er op de melding geklikt wordt.
                            .setSmallIcon(R.drawable.ic_statusbar_pv) //
                            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) //
                            .setTicker(text) //
                            .setWhen(System.currentTimeMillis()) // Set het tijdstip van de melding
                            .setAutoCancel(true) // Melding verwijderen als erop geklikt wordt.
                            .setContentTitle(getString(R.string.app_name))
                            .setStyle(new NotificationCompat.BigTextStyle().bigText(text)) // Style: Tekst over meerdere regels
                            .setContentText(text) // Tekst van de melding
                            .setLights(0xffffffff, 0, 0);

            if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_VIBRATE, false)) {
                notifBuilder.setVibrate(new long[] { 0, 1000 });
            }

            String ringtone = PrefUtils.getString(PrefUtils.NOTIFICATIONS_RINGTONE, null);
            if (ringtone != null && ringtone.length() > 0) {
                notifBuilder.setSound(Uri.parse(ringtone));
            }

            if (PrefUtils.getBoolean(PrefUtils.NOTIFICATIONS_LIGHT, false)) {
                notifBuilder.setLights(0xffffffff, 300, 1000);
            }

            NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            mNotifyMgr.notify(mNotificationId, notifBuilder.build());

        }

        PrefUtils.putInt(PrefUtils.NOTIFICATIONS_PREVIOUS_COUNT, newCount);
        mobilizeAllEntries();
        downloadAllImages();

        PrefUtils.putBoolean(PrefUtils.IS_REFRESHING, false);
    }
}

From source file:com.example.recordvoice.service.RecordService.java

private void startService() {
    if (!onForeground) {
        Log.d(Constants.TAG, "RecordService startService");
        Intent intent = new Intent(this, MainActivity.class);
        // intent.setAction(Intent.ACTION_VIEW);
        // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, intent, 0);

        Notification notification = new NotificationCompat.Builder(getBaseContext())
                .setContentTitle(this.getString(R.string.notification_title))
                .setTicker(this.getString(R.string.notification_ticker))
                .setContentText(this.getString(R.string.notification_text)).setSmallIcon(R.mipmap.ic_launcher)
                .setContentIntent(pendingIntent).setOngoing(true).getNotification();

        notification.flags = Notification.FLAG_NO_CLEAR;

        startForeground(1337, notification);
        onForeground = true;//from  www . j  a  va 2  s.co  m
    }
}

From source file:org.dkf.jmule.util.UIUtils.java

/**
 * Checks setting to show or not the transfers window right after a download has started.
 * This should probably be moved elsewhere (similar to GUIMediator on the desktop)
 *///from www.j a va2s. co m
public static void showTransfersOnDownloadStart(Context context) {
    if (ConfigurationManager.instance().showTransfersOnDownloadStart() && context != null) {
        Intent i = new Intent(context, MainActivity.class);
        i.setAction(ED2KService.ACTION_SHOW_TRANSFERS);
        i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        context.startActivity(i);
    }
}

From source file:io.selendroid.server.ServerInstrumentation.java

public void resumeActivity() {
    Activity activity = activitiesReporter.getBackgroundActivity();
    Log.d("TAG", "got background activity");
    if (activity == null) {
        SelendroidLogger.error("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;//w  ww. jav a 2 s. co m
    }
    // start now the new activity
    Log.d("TAG", "background activity is not null");
    Intent intent = new Intent(getTargetContext(), activity.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Log.d("TAG", "created intent and got target context");
    getTargetContext().startActivity(intent);
    Log.d("TAG", "got target context and started activity");
    activitiesReporter.setBackgroundActivity(null);
}