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.wmstein.transektcount.CountOptionsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.home) {
        Intent intent = NavUtils.getParentActivityIntent(this);
        intent.putExtra("section_id", section_id);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        NavUtils.navigateUpTo(this, intent);
    } else if (id == R.id.menuSaveExit) {
        saveData();/*from   w ww. j a  v  a2 s.com*/
        super.finish();
    }
    return super.onOptionsItemSelected(item);
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);//from w w  w.j a  v a  2s.  c om

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};

    //Stesso filtro del Manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(Variables_it.MIME_TEXT_PLAIN);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        throw new RuntimeException(Variables_it.MIME_ERROR);
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}

From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java

@SuppressWarnings("deprecation")
public void setServiceForeground(Context mContext) {
    final int myID = 9999;

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

    // This constructor is deprecated. Use Notification.Builder instead
    Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name),
            System.currentTimeMillis());

    // This method is deprecated. Use Notification.Builder instead.
    mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification),
            pendIntent);/*from www.  j a  v a  2 s  . co  m*/

    mNotification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(myID, mNotification);
}

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;/*from w w  w .  ja  v  a  2s . c  om*/
    }
    // 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);
}

From source file:com.weddingsingers.wsapp.fcm.MyFirebaseMessagingService.java

private void sendNotification(ChatMessage m) {

    Intent intent = new Intent(this, SplashActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(SplashActivity.EXTRA_FRAGNAME, ChattingActivity.class);

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

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512).setContentTitle("FCM Message")
            .setContentText(m.getSender().getName() + "?  - " + m.getMessage())
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

    /*Intent intent = new Intent(this, SplashActivity.class);
    intent.putExtra(ChattingActivity.EXTRA_USER, m.getSender());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.manifest_ic_wedding_singers_512)
        .setTicker("Chat Message")/* w  ww  . j av a  2s.co  m*/
        .setContentTitle("  ")
        .setContentText(m.getSender().getName() + "?  - " + m.getMessage())
        .setAutoCancel(true)
        .setDefaults(NotificationCompat.DEFAULT_ALL)
        .setContentIntent(pendingIntent);
            
    NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            
    notificationManager.notify(0 *//* ID of notification *//*, notificationBuilder.build());*/
}

From source file:de.uni_koblenz_landau.apow.PatientListActivity.java

/**
 * Start scanning for NFC tags./*from   www .ja  v  a  2s . c  o m*/
  * @param activity The Activity requesting to the foreground dispatch.
  * @param adapter The NfcAdapter used for the foreground dispatch.
 */
private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    if (adapter != null) {
        // Add intents for NFC.
        final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0,
                intent, 0);

        IntentFilter[] filters = new IntentFilter[1];
        String[][] techList = new String[][] {};

        filters[0] = new IntentFilter();
        filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
        filters[0].addCategory(Intent.CATEGORY_DEFAULT);

        adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
    }
}

From source file:com.linkbubble.MainApplication.java

public static boolean openInBrowser(Context context, String urlAsString, boolean showToastIfNoBrowser) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(urlAsString));
    intent.setFlags(//w w w  .j a v a2 s  . c  om
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    return MainApplication.openInBrowser(context, intent, showToastIfNoBrowser, false);
}

From source file:de.uni_koblenz_landau.apow.LoginActivity.java

/**
 * Start scanning for NFC tags.//from w ww  .ja  v  a 2 s  . co  m
 * @param activity The Activity requesting to the foreground dispatch.
 * @param adapter The NfcAdapter used for the foreground dispatch.
 */
private static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    if (adapter != null) {
        // Add intents for NFC.
        final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0,
                intent, 0);

        IntentFilter[] filters = new IntentFilter[1];
        String[][] techList = new String[][] {};

        filters[0] = new IntentFilter();
        filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
        filters[0].addCategory(Intent.CATEGORY_DEFAULT);
        try {
            filters[0].addDataType(MIME_TEXT_PLAIN);
        } catch (MalformedMimeTypeException e) {
            e.printStackTrace();
        }

        adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
    }
}

From source file:com.nononsenseapps.notepad.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }/* ww  w  .j  a v  a2 s  .  co  m*/
    // Handle your other action bar items...
    int itemId = item.getItemId();
    if (itemId == android.R.id.home) {
        if (showingEditor) {
            // Only true in portrait mode
            final View focusView = ActivityMain.this.getCurrentFocus();
            if (inputManager != null && focusView != null) {
                inputManager.hideSoftInputFromWindow(focusView.getWindowToken(),
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }

            // Should load the same list again
            // Try getting the list from the original intent
            final long listId = getListId(getIntent());

            final Intent intent = new Intent().setAction(Intent.ACTION_VIEW).setClass(ActivityMain.this,
                    ActivityMain_.class);
            if (listId > 0) {
                intent.setData(TaskList.getUri(listId));
            }

            // Set the intent before, so we set the correct
            // action bar
            setIntent(intent);
            while (getSupportFragmentManager().popBackStackImmediate()) {
                // Need to pop the entire stack and then load
            }

            reverseAnimation = true;
            Log.d("nononsenseapps fragment", "starting activity");

            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
        // else
        // Handled by drawer
        return true;
    } else if (itemId == R.id.drawer_menu_createlist) {
        // Show fragment
        DialogEditList_ dialog = DialogEditList_.getInstance();
        dialog.setListener(new EditListDialogListener() {

            @Override
            public void onFinishEditDialog(long id) {
                openList(id);
            }
        });
        dialog.show(getSupportFragmentManager(), "fragment_create_list");
        return true;
    } else if (itemId == R.id.menu_preferences) {
        Intent intent = new Intent();
        intent.setClass(this, PrefsActivity.class);
        startActivity(intent);
        return true;
    } else if (itemId == R.id.menu_donate) {
        try {
            mBillingHelper.launchPurchaseFlow(this, SKU_INAPP_PREMIUM, SKU_DONATE_REQUEST_CODE,
                    new IabHelper.OnIabPurchaseFinishedListener() {
                        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
                            if (result.isFailure()) {
                                Log.d("nononsenseapps billing", "Error purchasing: " + result);
                                return;
                            } else if (purchase.getSku().equals(SKU_INAPP_PREMIUM)) {
                                mHasPremiumAccess = true;
                                mDonatedInApp = true;
                                // Save in prefs
                                PreferenceManager.getDefaultSharedPreferences(ActivityMain.this).edit()
                                        .putBoolean(SKU_INAPP_PREMIUM, true).putBoolean(PREMIUMSTATUS, true)
                                        .commit();
                                // Update relevant parts of UI
                                updateUiDonate();
                                // Notify user of success
                                Toast.makeText(ActivityMain.this, R.string.premiums_unlocked_and_thanks,
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
        } catch (Exception e) {
            Log.d("nononsenseapps billing", "Shouldnt start two purchases! " + e.getLocalizedMessage());
        }
        return true;
    } else if (itemId == R.id.menu_sync) {
        handleSyncRequest();
        return true;
    } else if (itemId == R.id.menu_delete) {
        return false;
    } else {
        return false;
    }
}

From source file:com.nextgis.maplibui.service.TrackerService.java

private void initTargetIntent(String targetActivity) {
    Intent intentActivity = new Intent();

    if (!TextUtils.isEmpty(targetActivity)) {
        Class<?> targetClass = null;

        try {//from  w  ww.j  a  v  a 2s .c  o m
            targetClass = Class.forName(targetActivity);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        if (targetClass != null) {
            intentActivity = new Intent(this, targetClass);
        }
    }

    intentActivity.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mOpenActivity = PendingIntent.getActivity(this, 0, intentActivity, PendingIntent.FLAG_UPDATE_CURRENT);
}