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.android.utils.labeling.LabelOperationUtils.java

public static boolean startActivityAddLabelForNode(Context context, AccessibilityNodeInfoCompat node) {
    if (context == null || node == null) {
        return false;
    }// www.  j  a v  a 2s  .  co m

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        final Intent addIntent = new Intent(ACTION_ADD_LABEL);
        final Bundle extras = new Bundle();
        extras.putString(EXTRA_STRING_RESOURCE_NAME, node.getViewIdResourceName());
        addIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        addIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        addIntent.putExtras(extras);

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

From source file:br.org.projeto.vigilante.push.MyGcmListenerService.java

private void sendNotification(String message) {
    Intent intent = MainActivity_.intent(this).get();
    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)
            .setContentTitle(getString(R.string.app_name)).setSmallIcon(R.drawable.ic_stat_action_account_child)
            .setColor(getResources().getColor(R.color.colorPrimary))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:gov.in.bloomington.georeporter.fragments.ServersFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    JSONObject current_server = null;//from  w  w w . j av a2 s .  c  o  m
    try {
        current_server = mServers.getJSONObject(position);
    } catch (JSONException e) {
        // We'll just pass null to Preferences, which will wipe current_server
        // Once they get sent to Home, home will realize there isn't 
        // a current_server and send them back here
    }
    Preferences.setCurrentServer(current_server, getActivity());

    Intent i = new Intent(getActivity(), MainActivity.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
}

From source file:com.manning.androidhacks.hack046.helper.NotificationHelper.java

private static PendingIntent getDeletePendingIntent(Context ctx) {
    Intent intent = new Intent(ctx, MsgService.class);
    intent.setAction(MsgService.MSG_DELETE);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getService(ctx, 0, intent, 0);
}

From source file:adapter.notification.MyFcmListenerService.java

private void sendNotification(RemoteMessage.Notification notification) {
    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.drawable.ic_stat_utn).setContentTitle(notification.getTitle())
            .setContentText(notification.getBody()).setGroup(notification.getTag()).setAutoCancel(true)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.caldroid_holo_blue_dark))
            .setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:com.midisheetmusic.ChooseSongActivity.java

@Override
public void onCreate(Bundle state) {
    globalActivity = this;
    super.onCreate(state);

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

}

From source file:com.airflo.preferences.TypePreferenceActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent returnIntent = new Intent();
        returnIntent.putExtra("result", "justADummy");
        setResult(1, returnIntent);//w  ww  .j  av a  2  s.  c om
        Intent intent = new Intent(this, FlightListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //Resume saved State!   
        NavUtils.navigateUpTo(this, intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.andrewchelladurai.simplebible.utilities.NotificationDisplayer.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive: called");
    long when = System.currentTimeMillis();
    int MID = (int) when;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notIntent = new Intent(context, SimpleBibleActivity.class);
    notIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification_small_icon)
            .setContentTitle(context.getString(R.string.application_name))
            .setContentText(context.getString(R.string.notification_text)).setSound(alarmSound)
            .setAutoCancel(true).setWhen(when).setContentIntent(pendingIntent);

    notificationManager.notify(MID, builder.build());
    Log.d(TAG, "onReceive: reminder Created");
}

From source file:augsburg.se.alltagsguide.gcm.command.AnnouncementCommand.java

private void displayNotification(Context context, String message) {
    Ln.i("Displaying notification: " + message);
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0,
            new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher).setTicker(message)
                    .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
                    .setColor(ContextCompat.getColor(context, R.color.primary))
                    .setContentIntent(PendingIntent.getActivity(context, 0,
                            new Intent(context, OverviewActivity.class).setFlags(
                                    Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP),
                            0))/*www  . j  a v a  2s .c o  m*/
                    .setAutoCancel(true).build());
}

From source file:com.aqtx.app.main.activity.MainActivity.java

public static void start(Context context, Intent extras) {
    Intent intent = new Intent();
    intent.setClass(context, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    if (extras != null) {
        intent.putExtras(extras);//from   w  ww.  j a v a 2 s. c  o  m
    }
    context.startActivity(intent);
}