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.syncedsynapse.kore2.ui.TVShowsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_show_remote:
        // Starts remote
        Intent launchIntent = new Intent(this, RemoteActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(launchIntent);// w  ww .jav a  2s. com
        return true;
    case android.R.id.home:
        // Only respond to this if we are showing the episodeor show details in portrait
        // mode, which can be checked by checking if selected movie != -1, in which case we
        // should go back to the previous fragment, which is the list.
        // The default behaviour is handled by the nav drawer (open/close)
        if (selectedEpisodeId != -1) {
            selectedEpisodeId = -1;
            getSupportFragmentManager().popBackStack();
            return true;
        } else if (selectedTVShowId != -1) {
            selectedTVShowId = -1;
            selectedTVShowTitle = null;
            setupActionBar(null);
            getSupportFragmentManager().popBackStack();
            return true;
        }
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java

/**
 * Adds an onclick handler to the notification
 *///from w ww .j a v  a 2  s .  c  om
protected NotificationCompat.Builder setClickEvent(NotificationCompat.Builder builder) {
    int requestCode = new Random().nextInt();
    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, requestCode, launchIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    return builder.setContentIntent(contentIntent);
}

From source file:com.radiofarda.istgah.ui.PodcastsActivity.java

private void startFullScreenActivityIfNeeded(Intent intent) {
    if (intent != null && intent.getBooleanExtra(EXTRA_START_FULLSCREEN, false)) {
        Parcelable parcelableExtra = intent.getParcelableExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION);
        Intent fullScreenIntent = new Intent(this, FullScreenPlayerActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .putExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION, parcelableExtra);
        startActivity(fullScreenIntent);
    }//from ww w  .j  a  v a 2s  .  c om
}

From source file:it.polimi.guardian.authorityapp.GcmIntentService.java

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

    String[] data = msg.split("&");
    Event ev = new Event();
    ev.setLat(Double.parseDouble(data[1]));
    ev.setLng(Double.parseDouble(data[2]));
    ev.setDescription(data[3]);//from  w w w . j a  va2s.c o m
    ev.setEvent_time(data[4]);
    ev.setLocation_acc(Float.parseFloat(data[5]));
    ev.setType_of_event(data[6]);
    ev.setUser_phone(data[7]);
    ev.setAnonymous(Integer.parseInt(data[8]));
    ev.setAddress(data[9]);

    String anonymous = "";
    if (ev.getAnonymous() == 1)
        anonymous = "Anonymous tip:";
    else
        anonymous = ev.getUser_phone() + " ";

    Intent notificationIntent = new Intent(getApplicationContext(), MapActivity.class);

    notificationIntent.putExtra("notificationFlag", true);
    notificationIntent.putExtra("lat", ev.getLat());
    notificationIntent.putExtra("lng", ev.getLng());
    notificationIntent.putExtra("eventDescription", ev);

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(), 0,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = null;
    switch (data[6]) {
    case "F":
        mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.flame_gray)
                .setDefaults(Notification.DEFAULT_SOUND).setContentTitle("Alert!")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(anonymous + " " + data[3]))
                .setContentText(anonymous + " " + data[3]);
        break;
    case "P":
        mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.police_badge_gray)
                .setContentTitle("Alert!").setDefaults(Notification.DEFAULT_SOUND)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(anonymous + " " + data[3]))
                .setContentText(anonymous + " " + data[3]);
        break;
    case "E":
        mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ambulance_gray)
                .setContentTitle("Alert!").setDefaults(Notification.DEFAULT_SOUND)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(anonymous + " " + data[3]))
                .setContentText(anonymous + " " + data[3]);
        break;
    }

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

From source file:com.nextgis.ngm_clink_monitoring.adapters.FoclSyncAdapter.java

public static void sendNotification(Context context, int notificationType, String errorMsg) {
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
            .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()).setAutoCancel(true)
            .setOngoing(false);//from   w  ww.  ja va 2  s  . com

    switch (notificationType) {
    case FoclSyncAdapter.IS_STARTED:
        builder.setProgress(0, 0, true).setSmallIcon(R.drawable.ic_sync_started)
                .setTicker(context.getString(R.string.sync_started))
                .setContentTitle(context.getString(R.string.synchronization))
                .setContentText(context.getString(R.string.sync_progress));
        break;

    case FoclSyncAdapter.IS_FINISHED:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_finished)
                .setTicker(context.getString(R.string.sync_finished))
                .setContentTitle(context.getString(R.string.synchronization))
                .setContentText(context.getString(R.string.sync_finished));
        break;

    case FoclSyncAdapter.IS_CANCELED:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_error)
                .setTicker(context.getString(R.string.sync_canceled))
                .setContentTitle(context.getString(R.string.synchronization))
                .setContentText(context.getString(R.string.sync_canceled));
        break;

    case FoclSyncAdapter.IS_ERROR:
        builder.setProgress(0, 0, false).setSmallIcon(R.drawable.ic_sync_error)
                .setTicker(context.getString(R.string.sync_error))
                .setContentTitle(context.getString(R.string.sync_error)).setContentText(errorMsg);
        break;
    }

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFY_ID, builder.build());
}

From source file:net.networksaremadeofstring.rhybudd.WriteNFCActivity.java

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

    BugSenseHandler.initAndStartSession(WriteNFCActivity.this, "44a76a8c");

    setContentView(R.layout.write_tag_activity);

    try {// w ww  . ja v  a2 s. co  m
        getActionBar().setSubtitle(getString(R.string.NFCTitle));
        getActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (Exception gab) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", gab);
    }

    //Quick test
    try {
        UID = getIntent().getExtras().getString(PAYLOAD_UID).replace("/zport/dmd/Devices/", "");

        aaRecord = NdefRecord.createApplicationRecord("net.networksaremadeofstring.rhybudd");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            //idRecord = NdefRecord.createExternal("rhybudd:tag", "z", UID.getBytes(Charset.forName("US-ASCII")));
            idRecord = NdefRecord.createMime("application/vnd.rhybudd.device", UID.getBytes());
        } else {
            idRecord = NdefRecord.createUri("rhybudd://" + UID);
        }

        ((TextView) findViewById(R.id.SizesText)).setText("This payload is "
                + (aaRecord.toByteArray().length + idRecord.toByteArray().length)
                + " bytes.\n\nAn ultralight can store up to 46 bytes.\nAn Ultralight C or NTAG203 can store up to 137 bytes.\nDespite the name a 1K can only store up to 716 bytes.");
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", e);
        try {
            Toast.makeText(this, "Sorry there was error parsing the passed UID, we cannot continue.",
                    Toast.LENGTH_SHORT).show();
        } catch (Exception t) {
            BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", t);
        }

        finish();
    }

    try {
        mAdapter = NfcAdapter.getDefaultAdapter(this);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate getDefaultAdapter", e);
        mAdapter = null;
    }

    try {
        pendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate pendingIntent", e);
    }

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);

    try {
        ndef.addDataType("*/*"); /* Handles all MIME based dispatches.
                                    You should specify only the ones that you need. */
    } catch (IntentFilter.MalformedMimeTypeException e) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate", e);
        throw new RuntimeException("fail", e);
    }

    try {
        IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
        intentFiltersArray = new IntentFilter[] { ndef, td };

        techListsArray = new String[][] { new String[] { NfcF.class.getName(), NfcA.class.getName(),
                Ndef.class.getName(), NdefFormatable.class.getName() } };
    } catch (Exception e) {
        BugSenseHandler.sendExceptionMessage("WriteNFCActivity", "onCreate IntentFilter", e);
    }

    CreateHandlers();
}

From source file:com.radiofarda.istgah.ui.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);/*w ww.  j ava 2s  . co  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);
            MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
            MediaMetadataCompat metadata = controller.getMetadata();
            if (metadata != null) {
                intent.putExtra(PodcastsActivity.EXTRA_CURRENT_MEDIA_DESCRIPTION, metadata.getDescription());
            }
            startActivity(intent);
        }
    });
    return rootView;
}

From source file:com.bayapps.android.robophish.ui.MusicPlayerActivity.java

private void startFullScreenActivityIfNeeded(Intent intent) {
    if (intent != null && intent.getBooleanExtra(EXTRA_START_FULLSCREEN, false)) {
        Intent fullScreenIntent = new Intent(this, FullScreenPlayerActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .putExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION,
                        intent.getParcelableExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION));
        startActivity(fullScreenIntent);
    }//from w  w  w  .  ja  va  2s .c o  m
}

From source file:com.veniosg.dir.android.util.Notifier.java

public static void showCompressDoneNotification(boolean success, int notId, File zipFile, Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    if (!shouldShowDoneNotification(notId, success)) {
        notificationManager.cancel(notId);
    } else {/*from  ww w. j  a v a  2s  .  co  m*/
        Intent browseIntent = new Intent(context, FileManagerActivity.class);
        browseIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        browseIntent.setData(Uri.fromFile(zipFile.getParentFile()));

        Notification not = new NotificationCompat.Builder(context, CHANNEL_FILEOPS).setAutoCancel(true)
                .setContentTitle(context.getString(
                        success ? R.string.notif_compressed_success : R.string.notif_compressed_fail))
                .setContentText(zipFile.getName())
                .setContentIntent(getActivity(context, 0, browseIntent, FLAG_CANCEL_CURRENT)).setOngoing(false)
                .setPriority(NotificationCompat.PRIORITY_DEFAULT)
                .setSmallIcon(R.drawable.ic_stat_notify_compress_5)
                .setTicker(context.getString(
                        success ? R.string.notif_compressed_success : R.string.notif_compressed_fail))
                .setOnlyAlertOnce(true).build();

        notificationManager.notify(notId, not);
    }
}