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:Main.java

private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(context, classes);
    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }//from   w w w . ja v  a 2 s . com
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:Main.java

public static void navigateUp(Activity activity, Bundle extras) {
    Intent upIntent = NavUtils.getParentActivityIntent(activity);
    if (upIntent != null) {
        if (extras != null) {
            upIntent.putExtras(extras);/*from   w  w w . j a va  2 s .  com*/
        }
        if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
            // This activity is NOT part of this app's task, so create a new task
            // when navigating up, with a synthesized back stack.
            TaskStackBuilder.create(activity)
                    // Add all of this activity's parents to the back stack.
                    .addNextIntentWithParentStack(upIntent)
                    // Navigate up to the closest parent.
                    .startActivities();
        } else {
            // This activity is part of this app's task, so simply
            // navigate up to the logical parent activity.
            // According to http://stackoverflow.com/a/14792752/2420519
            //NavUtils.navigateUpTo(activity, upIntent);
            upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            activity.startActivity(upIntent);
        }
    }
    activity.finish();
}

From source file:Main.java

/**
 * start app/*from  w  w w .  jav  a2s .  c  om*/
 *
 * @param ctx
 * @param packageName
 */
public static void startApp(Context ctx, String packageName) {

    if (!isAppInstalled(ctx, packageName)) {
        return;
    }

    PackageManager packageManager = ctx.getPackageManager();
    Intent intent = packageManager.getLaunchIntentForPackage(packageName);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
            | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    ctx.startActivity(intent);
}

From source file:Main.java

private static void shareImageOnFacebook(String imagePath, Context context) {

    Log.d("CitationsManager-ShareOnFb", "sharing the image " + imagePath);
    Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    // shareIntent.putExtra(Intent.EXTRA_TEXT, "www.google.com");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(imagePath)));
    PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
    for (final ResolveInfo app : activityList) {

        Log.d("CitationsManager-ShareOnFb", app.activityInfo.name);
        if ((app.activityInfo.name).contains("com.facebook") && !(app.activityInfo.name).contains("messenger")
                && !(app.activityInfo.name).contains("pages")) {
            final ActivityInfo activity = app.activityInfo;
            final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
            shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            shareIntent.setComponent(name);
            context.startActivity(shareIntent);
            break;
        }/*w  ww.  ja va2s.  co m*/
    }

}

From source file:Main.java

public static boolean startActivity(Context a, String packageName) {
    PackageManager pm = a.getPackageManager();
    boolean result = true;
    try {/*from  w w w  .ja  v  a 2s .  c  o  m*/
        Intent intent = pm.getLaunchIntentForPackage(packageName);
        if (intent != null) {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            //         intent.addCategory(Intent.CATEGORY_LAUNCHER);
            a.startActivity(intent);
        } else {
            result = startActivityUsingScheme(a, packageName);
        }
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = startActivityUsingScheme(a, packageName);
    }
    return result;
}

From source file:com.kku.apps.pricesearch.util.Utils.java

public static void goHome(Context context) {
    final Intent intent = new Intent(context, HomeActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);//w w w .j  a  va2 s.c om
    ((Activity) context).overridePendingTransition(R.anim.fade, R.anim.hold);
}

From source file:com.apptentive.android.example.push.MyGcmListenerService.java

@Override
public void onMessageReceived(String from, Bundle data) {
    String title = data.getString("gcm.notification.title");
    String body = data.getString("gcm.notification.body");
    ApptentiveLog.e("From: " + from);
    ApptentiveLog.e("Title: " + title);
    ApptentiveLog.e("Body: " + body);

    Intent intent = new Intent(this, ExampleActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Apptentive.setPendingPushNotification(data);

    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.notification).setContentTitle(title).setContentText(body)
            .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);

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

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

From source file:gov.nasa.arc.geocam.talk.UIUtils.java

/**
 * Show the {@link GeoCamTalkMapActivity} for a given message.
 *
 * @param context The current activity context
 * @param talkMessage The {@link GeoCamTalkMessage} that the map activity will display
 *///ww w.  j a va  2s  .  co m
public static void showMapView(Context context, GeoCamTalkMessage talkMessage) {
    final Intent intent = new Intent(context, GeoCamTalkMapActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(context.getString(R.string.latitude), talkMessage.getLatitude());
    intent.putExtra(context.getString(R.string.longitude), talkMessage.getLongitude());
    intent.putExtra(context.getString(R.string.accuracy), talkMessage.getAccuracy());
    context.startActivity(intent);
}

From source file:Main.java

public static boolean startActivity(Activity a, String packageName, Bundle args) {
    PackageManager pm = a.getPackageManager();
    boolean result = true;
    try {/*from  w  w  w . j  av a2s .c  o m*/
        Intent intent = pm.getLaunchIntentForPackage(packageName);
        if (null != intent) {
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            if (args != null)
                intent.putExtras(args);
            a.startActivity(intent);
        } else {
            result = startActivityUsingScheme(a, packageName, args);
        }
    } catch (Exception e) {
        Log.e(a.getClass().getName(), e.getMessage(), e);
        result = startActivityUsingScheme(a, packageName, args);
    }
    return result;
}

From source file:com.acrylicgoat.houstonbicyclemuseum.fragment.LandingFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ImageView iv = (ImageView) view.findViewById(R.id.landingImage1);
    iv.setImageResource(R.drawable.launch1);
    iv.setClickable(true);//from   ww  w .ja v a2  s .  co  m
    iv.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //open about us
            Intent aboutIntent = new Intent(getActivity().getApplicationContext(), AboutUsActivity.class);
            aboutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(aboutIntent);
        }
    });
    ImageView iv2 = (ImageView) view.findViewById(R.id.landingImage2);
    iv2.setImageResource(R.drawable.launch2);
    iv2.setClickable(true);
    iv2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //open gallery
            Intent mainIntent = new Intent(getActivity().getApplicationContext(), ViewPagerActivity.class);
            mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(mainIntent);

        }
    });

}