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:org.wso2.iot.agent.services.operation.OperationManager.java

/**
 * Ring the device./*  ww w .  jav  a2  s .c o  m*/
 *
 * @param operation - Operation object.
 */
public void ringDevice(org.wso2.iot.agent.beans.Operation operation) {
    operation.setStatus(resources.getString(R.string.operation_value_completed));
    resultBuilder.build(operation);
    Intent intent = new Intent(context, AlertActivity.class);
    intent.putExtra(resources.getString(R.string.intent_extra_type),
            resources.getString(R.string.intent_extra_ring));
    intent.putExtra(resources.getString(R.string.intent_extra_message_text),
            resources.getString(R.string.intent_extra_stop_ringing));
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Ringing is activated on the device");
    }
}

From source file:com.anhuioss.crowdroid.activity.MoreFunctionActivity.java

private void confirmLogoutDialog() {
    AlertDialog.Builder dlg = new AlertDialog.Builder(this);
    dlg.setTitle(R.string.logout);//from   w w w.ja v a 2s.c o  m
    dlg.setMessage(getResources().getString(R.string.wheter_to_logout))
            .setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {

                    //
                    NotificationManager notificationManager = (NotificationManager) getSystemService(
                            NOTIFICATION_SERVICE);
                    notificationManager.cancelAll();

                    Intent i = new Intent(MoreFunctionActivity.this, LoginActivity.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.putExtra("autoLogin", false);
                    startActivity(i);
                    //                        android.os.Process
                    //                              .killProcess(android.os.Process.myPid());
                }
            }).setNegativeButton(getResources().getString(R.string.cancel),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    })
            .create().show();

}

From source file:name.setup.dance.StepService.java

/**
 * Show a notification while this service is running.
 *///www  .  java2  s  . co m
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent DanceStepAppIntent = new Intent();
    DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class));
    DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

private static void generateImageNotification(Context context, String title, String message, String url,
        String image_url, String large_icon) {

    // The bitmap to download
    Bitmap message_bitmap = null;/*ww w .  j  av a  2s .  com*/
    // Should we download the image?
    if ((image_url != null) && (!image_url.equals(""))) {
        message_bitmap = AirBopImageDownloader.downloadBitmap(image_url, context);
    }
    // If we didn't get the image, we're out of here
    if (message_bitmap == null) {
        generateNotification(context, title, message, url, large_icon);
        return;
    }
    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);

    int icon = airBop_settings.mNotificationIcon;

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }

    Intent notificationIntent = null;
    if ((url == null) || (url.equals(""))) {
        //just bring up the app
        if (context != null) {
            ClassLoader class_loader = context.getClassLoader();
            if (class_loader != null) {
                try {
                    if (airBop_settings.mDefaultNotificationClass != null) {
                        notificationIntent = new Intent(context,
                                Class.forName(airBop_settings.mDefaultNotificationClass));
                    }
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } else {
        //Launch the URL
        notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse(url));
        notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    }
    PendingIntent intent = null;
    // set intent so it does not start a new activity
    if (notificationIntent != null) {
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    }

    Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(message_bitmap));
    if (intent != null) {
        notificationBuilder.setContentIntent(intent);
    }
    if (icon != 0) {
        notificationBuilder.setSmallIcon(icon);
    }
    Notification notification = notificationBuilder.build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}

From source file:com.gb.cwsup.activity.order.WaitSureOrderActivity.java

/**
 * ?//  www  .ja  v  a  2 s. c o m
 */
private void startscan() {
    if (dialog != null) {
        dialog.dismiss();
    }
    Intent insureintent = new Intent(WaitSureOrderActivity.this, MipcaActivityCapture.class);
    insureintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(insureintent, SCANNIN_GREQUEST_CODE);
}

From source file:com.dnielfe.manager.AppManager.java

private void createshortcut() {
    Intent shortcutIntent = new Intent(AppManager.this, AppManager.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);

    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.appmanager));
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(AppManager.this, R.drawable.type_apk));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    AppManager.this.sendBroadcast(addIntent);

    Toast.makeText(AppManager.this, getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
}

From source file:io.coldstart.android.GCMIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void SendInboxStyleNotification(String alertCount, String alertTime, String hostname,
        String payloadDetails) {/*from w  w w  .ja  v a2  s  .c  o  m*/
    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    String Line1 = "", Line2 = "", Line3 = "", Line4 = "", Line5 = "";
    String[] separatedLines = payloadDetails.split("\n");

    int payloadLength = separatedLines.length;
    if (payloadLength > 5)
        payloadLength = 5;

    for (int i = 0; i < payloadLength; i++) {
        try {
            switch (i) {
            case 0: {
                Line1 = separatedLines[i];
            }
                break;

            case 1: {
                Line2 = separatedLines[i];
            }
                break;

            case 2: {
                Line3 = separatedLines[i];
            }
                break;

            case 3: {
                Line4 = separatedLines[i];
            }
                break;

            case 4: {
                Line5 = separatedLines[i];
            }
                break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Notification notification = new Notification.InboxStyle(
            new Notification.Builder(this).setContentTitle("SNMP trap received")
                    .setContentText(Line1 + " " + Line2 + "...").setSmallIcon(R.drawable.ic_stat_alert)
                    .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri)
                    .setPriority(Notification.PRIORITY_MAX).setTicker("New SNMP traps have been received")
                    .setContentIntent(PendingIntent.getActivity(this, 0,
                            new Intent(this, TrapListActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                                    .putExtra("forceRefresh", true),
                            0))).setBigContentTitle("New SNMP traps have been received")
                                    .setSummaryText("Launch ColdStart.io to Manage These Events").addLine(Line1)
                                    .addLine(Line2).addLine(Line3).addLine(Line4).build();

    notification.defaults |= Notification.DEFAULT_SOUND;

    mNM.notify(43523, notification);
}

From source file:org.wso2.emm.agent.services.operation.OperationManager.java

/**
 * Ring the device./*from   w  w  w.  j  ava 2  s  . c o m*/
 *
 * @param operation - Operation object.
 */
public void ringDevice(org.wso2.emm.agent.beans.Operation operation) {
    operation.setStatus(resources.getString(R.string.operation_value_completed));
    resultBuilder.build(operation);
    Intent intent = new Intent(context, AlertActivity.class);
    intent.putExtra(resources.getString(R.string.intent_extra_type),
            resources.getString(R.string.intent_extra_ring));
    intent.putExtra(resources.getString(R.string.intent_extra_message_text),
            resources.getString(R.string.intent_extra_stop_ringing));
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Ringing is activated on the device");
    }
}

From source file:com.frostwire.android.gui.util.UIUtils.java

public static void goToFrostWireMainActivity(Activity activity) {
    final Intent intent = new Intent(activity, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    activity.startActivity(intent);/*from   w w  w .j a  v  a 2 s .co m*/
    activity.finish();
    activity.overridePendingTransition(0, 0);
}

From source file:com.adarshahd.indianrailinfo.donate.TrainEnquiry.java

private void startDetailsActivity() {

    //For testing!!!
    /*File file = new File("/sdcard/train_details_trn_number.html");
    String result = "";/*from  ww  w .ja  v a2s  .  c o  m*/
    try {
    FileInputStream stream = new FileInputStream(file);
    InputStreamReader readerStream = new InputStreamReader(stream);
    BufferedReader reader = new BufferedReader(readerStream);
    String str;
    while((str = reader.readLine()) != null) {
        result += str;
    }
    } catch (IOException e) {
    e.printStackTrace();
    }*/

    if (mPage.contains("unavailable")) {
        TextView tv = new TextView(mActivity);
        tv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL));
        tv.setTextColor(Color.RED);
        tv.setTextSize(20);
        tv.setText(
                "Response from server: \n\n\"The requested service is currently unavailable. Please try again later\"");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(tv);
        return;
    }
    if (mPage.contains("invalid")) {
        TextView tv = new TextView(mActivity);
        tv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL));
        tv.setTextColor(Color.RED);
        tv.setTextSize(20);
        tv.setText("Invalid Station code! Please select the station code from drop down list.");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(tv);
        return;
    }
    if (mPage.contains("No Matching Trains")) {
        TextView tv = new TextView(mActivity);
        tv.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL));
        tv.setTextColor(Color.RED);
        tv.setTextSize(20);
        tv.setText("No Matching train found! Please check the train number/name");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(tv);
        return;
    }

    //put the required intent data and start TrainEnquiryDetails activity.
    Intent intent = new Intent(this, TrainEnquiryDetails.class);
    intent.putExtra(TRAIN, mTrainNumber);
    intent.putExtra(SEARCH, searchUsingTrnNumber);
    intent.putExtra(PAGE, mPage);
    intent.putExtra(SRC, mACTFrom.getText().toString());
    intent.putExtra(DST, mACTTo.getText().toString());
    intent.putExtra(DAY_TRAVEL, mCal.get(Calendar.DAY_OF_MONTH));
    intent.putExtra(MONTH_TRAVEL, mCal.get(Calendar.MONTH));
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    //Try to parse the mTrainNumber;
    try {
        Integer.parseInt(mTrainNumber);
        isInteger = true;
    } catch (Exception e) {
        isInteger = false;
    }
    intent.putExtra(ISINT, isInteger);
    startActivity(intent);
}