Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TOP

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TOP

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

Click Source Link

Document

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

Usage

From source file:com.andryr.guitartuner.SettingsActivity.java

@Override
public void onBackPressed() {
    if (mShouldRestart) {
        Intent i = getPackageManager().getLaunchIntentForPackage(getPackageName());
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);//from  ww w.j  ava  2s  . c om
    } else {
        super.onBackPressed();
    }
}

From source file:com.android.elixr.ElixrGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.// w  w  w. jav  a 2s .  c om
 */
private void sendNotification(ReportData reportData) {
    Intent intent = new Intent(this, ReportDataActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(REPORT_DATA_KEY, reportData);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.ic_menu_view).setContentTitle("GCM Message")
            .setContentText(reportData.getPatientName()).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:be.ppareit.swiftp.gui.FsNotification.java

private void setupNotification(Context context) {
    Cat.d("Setting up the notification");
    // Get NotificationManager reference
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    // get ip address
    InetAddress address = FsService.getLocalInetAddress();
    if (address == null) {
        Cat.w("Unable to retrieve the local ip address");
        return;/*from  w ww . jav a 2  s  .co m*/
    }
    String iptext = "ftp://" + address.getHostAddress() + ":" + FsSettings.getPortNumber() + "/";

    // Instantiate a Notification
    int icon = R.mipmap.notification;
    CharSequence tickerText = String.format(context.getString(R.string.notification_server_starting), iptext);
    long when = System.currentTimeMillis();

    // Define Notification's message and Intent
    CharSequence contentTitle = context.getString(R.string.notification_title);
    CharSequence contentText = String.format(context.getString(R.string.notification_text), iptext);

    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, 0);

    int stopIcon = android.R.drawable.ic_menu_close_clear_cancel;
    CharSequence stopText = context.getString(R.string.notification_stop_text);
    Intent stopIntent = new Intent(FsService.ACTION_STOP_FTPSERVER);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(context, 0, stopIntent,
            PendingIntent.FLAG_ONE_SHOT);

    int preferenceIcon = android.R.drawable.ic_menu_preferences;
    CharSequence preferenceText = context.getString(R.string.notif_settings_text);
    Intent preferenceIntent = new Intent(context, MainActivity.class);
    preferenceIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent preferencePendingIntent = PendingIntent.getActivity(context, 0, preferenceIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setContentTitle(contentTitle)
            .setContentText(contentText).setContentIntent(contentIntent).setSmallIcon(icon)
            .setTicker(tickerText).setWhen(when).setOngoing(true)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX)
            .addAction(stopIcon, stopText, stopPendingIntent)
            .addAction(preferenceIcon, preferenceText, preferencePendingIntent).setShowWhen(false).build();

    // Pass Notification to NotificationManager
    nm.notify(NOTIFICATION_ID, notification);

    Cat.d("Notification setup done");
}

From source file:jp.co.ipublishing.esnavi.helpers.android.AppActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int id = item.getItemId();

    if (id == android.R.id.home) {
        final Intent intent = new Intent(this, MapActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);/*from w  w w  .ja  va2  s . co  m*/
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.geekandroid.sdk.sample.JPushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();//from w  w  w.  j  a  va  2s  .c  om
    Log.d(TAG, "[JPushReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));

    if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
        Log.d(TAG, "[JPushReceiver] Registration Id : " + regId);
        //send the Registration Id to your server...

    } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ???: "
                + bundle.getString(JPushInterface.EXTRA_MESSAGE));
        processCustomMessage(context, bundle);

    } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ??");
        int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
        Log.d(TAG, "[JPushReceiver] ??ID: " + notifactionId);

    } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] ");
        JPushImpl.getInstance().clearAllNotifications();

        //Activity
        Intent i = new Intent(context, JPushOpenActivity.class);
        i.putExtras(bundle);
        //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(i);

    } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
        Log.d(TAG, "[JPushReceiver] RICH PUSH CALLBACK: "
                + bundle.getString(JPushInterface.EXTRA_EXTRA));
        //? JPushInterface.EXTRA_EXTRA ??Activity ..

    } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
        boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
        Log.w(TAG, "[JPushReceiver]" + intent.getAction() + " connected state change to " + connected);
    } else {
        Log.d(TAG, "[JPushReceiver] Unhandled intent - " + intent.getAction());
    }
}

From source file:com.android.anton.pushnotificationwithgcm.GCMUtil.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./* w w w . ja  va  2s .com*/
 */
private void sendNotification(String message) {

    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_notification).setContentTitle("Live Document Translator")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    //        int notificationCount = getSharedPreferences("Notification", MODE_PRIVATE).getInt("Count", 0);
    //        notificationCount ++;
    //        SharedPreferences.Editor editor = this.getSharedPreferences("Notification", MODE_PRIVATE).edit();
    //        editor.putInt("Count", notificationCount);
    //        editor.commit();
    //
    //        boolean success = ShortcutBadger.applyCount(getApplicationContext(), notificationCount);

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

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

From source file:com.ecml.ChooseSongActivity.java

@Override
public void onCreate(Bundle state) {

    globalActivity = this;
    super.onCreate(state);

    // Set the Action Bar Title of the Activity (corresponding to the first Tab)
    setTitle("ECML: Choose Song");

    Bitmap allFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.allfilesicon);
    Bitmap recentFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.recentfilesicon);
    Bitmap browseFilesIcon = BitmapFactory.decodeResource(this.getResources(), R.drawable.browsefilesicon);

    final TabHost tabHost = getTabHost();

    tabHost.addTab(tabHost.newTabSpec("All").setIndicator("All", new BitmapDrawable(allFilesIcon))
            .setContent(new Intent(this, AllSongsActivity.class)));

    tabHost.addTab(tabHost.newTabSpec("Recent").setIndicator("Recent", new BitmapDrawable(recentFilesIcon))
            .setContent(new Intent(this, RecentSongsActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));

    tabHost.addTab(tabHost.newTabSpec("Browse").setIndicator("Browse", new BitmapDrawable(browseFilesIcon))
            .setContent(new Intent(this, FileBrowserActivity.class)));

    tabHost.setOnTabChangedListener(this);
}

From source file:app.com.locationfetch.GeofenceTransitionsIntentService.java

private void sendNotification(String s) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Location Push").setContentText(s)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

    notificationManager.notify(0, notificationBuilder.build());
}

From source file:io.selendroid.ServerInstrumentation.java

public void startActivity(Class activity) {
    if (activity == null) {
        SelendroidLogger.log("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;//from   w w  w .  j a  v  a 2s  .  c  o m
    }
    finishAllActivities();
    // start now the new activity
    Intent intent = new Intent(getTargetContext(), activity);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    Activity a = startActivitySync(intent);
}

From source file:com.android.utils.labeling.LabelOperationUtils.java

public static boolean startActivityRemoveLabel(Context context, Label label) {
    if (context == null || label == null) {
        return false;
    }//  ww  w. j  a  v a2  s.c o m

    final Intent removeIntent = new Intent(ACTION_REMOVE_LABEL);
    final Bundle extras = new Bundle();
    extras.putLong(EXTRA_LONG_LABEL_ID, label.getId());
    removeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    removeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    removeIntent.putExtras(extras);

    try {
        context.startActivity(removeIntent);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}