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.androidexperiments.tunnelvision.SplashScreenActivity.java

protected void moveToMainActivity() {
    if (mIsExiting) {
        //make sure this doesnt happen twice
        return;//w ww  .j  av a2 s .c om
    }
    mIsExiting = true;
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();
}

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

@Override
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 .jav  a  2s  . co m
        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.airflo.FlightDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        Intent intent = new Intent(this, FlightListActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Resume saved
        // State!
        NavUtils.navigateUpTo(this, intent);
        return true;
    }/*from  w  w  w .  ja v  a2 s.  c o m*/
    return super.onOptionsItemSelected(item);
}

From source file:com.target.plugins.PdfViewer.java

public String showPdf(String fileName) {

    File file = new File(fileName);

    if (file.exists()) {
        try {//from w w  w .  java2  s .c om
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            //intent.setData(Uri.parse(fileName));
            this.ctx.startActivity(intent);
            return "";
        } catch (android.content.ActivityNotFoundException e) {
            System.out.println("PdfViewer: Error loading url " + fileName + ":" + e.toString());
            return e.toString();
        }

    } else {
        return "file not found";
    }

}

From source file:com.android.nunes.sophiamobile.gsm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*from   w w w.  j  a  v a 2 s.  c  o  m*/
 */
private void sendNotification(String message) {

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

    //   AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    // alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1, pendingIntent);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("Ateno para livro em atraso")
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

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

private static PendingIntent getPendingIntent(Context ctx) {
    Intent intent = new Intent(ctx, MsgActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getActivity(ctx, 0, intent, 0);
}

From source file:com.appteam.nimbus.activity.homeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    personalData = new PersonalData(this);
    if (personalData.getStatus() == false) {
        Intent i = new Intent(homeActivity.this, Login.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(i);/*w ww  .  j ava 2  s.  com*/
        finish();
    }

    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ImageView icon1 = (ImageView) findViewById(R.id.icon1);
    ImageView arrow1 = (ImageView) findViewById(R.id.arrow1);
    ImageView icon2 = (ImageView) findViewById(R.id.icon2);
    ImageView arrow2 = (ImageView) findViewById(R.id.arrow2);
    ImageView icon3 = (ImageView) findViewById(R.id.icon3);
    ImageView arrow3 = (ImageView) findViewById(R.id.arrow3);
    ImageView icon4 = (ImageView) findViewById(R.id.icon4);
    ImageView arrow4 = (ImageView) findViewById(R.id.arrow4);
    ImageView icon5 = (ImageView) findViewById(R.id.icon5);
    ImageView arrow5 = (ImageView) findViewById(R.id.arrow5);

    final int newColor = getResources().getColor(R.color.new_color);
    icon1.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    arrow1.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    icon2.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    arrow2.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    icon3.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    arrow3.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    icon4.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    arrow4.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    icon5.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);
    arrow5.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    findViewById(R.id.department).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(homeActivity.this, DepartmentalTeam.class));
            overridePendingTransition(R.anim.open_next, R.anim.open_main);
        }
    });

    findViewById(R.id.coreteam).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(homeActivity.this, CoreTeamActivity.class));
            overridePendingTransition(R.anim.open_next, R.anim.open_main);
        }
    });

    findViewById(R.id.event).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(homeActivity.this, EventActivity.class));
            overridePendingTransition(R.anim.open_next, R.anim.open_main);
        }
    });
    findViewById(R.id.welcome).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(homeActivity.this, AboutNimbusSplash.class);
            intent.putExtra(ABOUT_NIMBUS, "rule");
            startActivity(intent);
        }
    });
    findViewById(R.id.sponsors).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(homeActivity.this, SponserActivity.class));
            overridePendingTransition(R.anim.open_next, R.anim.open_main);
        }
    });
}

From source file:assistance.shopping.msc.assistant.support.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message shoppingBroadcastDescription received.
 *//* w  w  w.  j  ava  2 s. co m*/
private void sendNotification(String messageBody) {
    Intent intent = new Intent(this, LoginActivity.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_ic_notification).setContentTitle("FCM Message")
            .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

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

From source file:com.ibm.bluelist.MainActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    SensoroManager sensoroManager = SensoroManager.getInstance(getApplicationContext());
    blApplication = (MessengerApplication) getApplication();
    if (getIntent().getBooleanExtra("EXIT", false)) {
        finish();//  w ww. j a  v a2 s.c  o m
    }
    myIntent = new Intent(getApplicationContext(), PostTrackingNotifier.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if (sensoroManager.isBluetoothEnabled()) {
        /**
         * Enable cloud service (upload sensor data, including battery status, UMM, etc.)Without setup, it keeps in closed status as default.
         **/
        sensoroManager.setCloudServiceEnable(true);
        /**
         * Enable SDK service
         **/
        try {
            sensoroManager.startService();
        } catch (Exception e) {
            e.printStackTrace(); // Fetch abnormal info
        }
    } else {
        Intent bluetoothIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(bluetoothIntent, REQUEST_ENABLE_BT);
    }
    BeaconManagerListener beaconManagerListener = new BeaconManagerListener() {
        ArrayList<String> foundSensors = new ArrayList<String>();

        @Override
        public void onUpdateBeacon(ArrayList<Beacon> beacons) {
            // Refresh sensor info
            for (Beacon beacon : beacons) {
                if (true) {
                    if (beacon.getMovingState() == Beacon.MovingState.DISABLED) {
                        // Disable accelerometer
                        System.out.println(beacon.getSerialNumber() + "Disabled");
                        Log.d("Main", beacon.getSerialNumber() + "Disabled");

                    } else if (beacon.getMovingState() == Beacon.MovingState.STILL) {
                        // Device is at static
                        Log.d("Main", beacon.getSerialNumber() + "static");
                        Log.d("Main", beacon.getProximityUUID());
                        if (!foundSensors.contains(beacon.getProximityUUID())) {
                            //String messageDisplay = "";
                            Log.d("Main", "getting Beacon Info");
                            foundSensors.add(beacon.getProximityUUID());
                            IBMCloudCode.initializeService();
                            IBMCloudCode myCloudCodeService = IBMCloudCode.getService();
                            String id = beacon.getProximityUUID();
                            String url = "/getNotification?id=" + id;
                            myCloudCodeService.get(url).continueWith(new Continuation<IBMHttpResponse, Void>() {

                                @Override
                                public Void then(Task<IBMHttpResponse> task) throws Exception {
                                    if (task.isCancelled()) {
                                        Log.e(CLASS_NAME,
                                                "Exception : Task" + task.isCancelled() + "was cancelled.");
                                    } else if (task.isFaulted()) {
                                        Log.e(CLASS_NAME, "Exception : " + task.getError().getMessage());
                                    } else {
                                        InputStream is = task.getResult().getInputStream();
                                        try {
                                            BufferedReader in = new BufferedReader(new InputStreamReader(is));
                                            String responseString = "";
                                            String myString = "";
                                            while ((myString = in.readLine()) != null)
                                                responseString += myString;

                                            in.close();
                                            Log.i(CLASS_NAME, "Response Body: " + responseString);
                                            JSONObject obj = new JSONObject(responseString);
                                            final String name = obj.getString("message");
                                            final String meets = obj.getString("meetups");

                                            /*Notification*/

                                            myIntent.putExtra("response", responseString);
                                            PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                                                    getApplicationContext(), 5, myIntent,
                                                    PendingIntent.FLAG_UPDATE_CURRENT);
                                            final NotificationCompat.Builder builder = new NotificationCompat.Builder(
                                                    getApplicationContext());
                                            builder.setSmallIcon(R.drawable.logo);
                                            builder.setContentTitle("IBM Beacons Messenger");
                                            builder.setContentText(name);
                                            builder.setContentIntent(pendingNotificationIntent);
                                            NotificationManager notificationManager = (NotificationManager) getSystemService(
                                                    Context.NOTIFICATION_SERVICE);
                                            notificationManager.notify(5, builder.build());

                                        } catch (IOException e) {
                                            e.printStackTrace();
                                        }

                                        Log.i(CLASS_NAME, "Response Status from login: "
                                                + task.getResult().getHttpResponseCode());
                                    }

                                    return null;
                                }

                            });

                        }
                        Log.d("Main", beacon.getMajor().toString());
                        Log.d("Main", beacon.getMinor().toString());
                        //Log.d("Main",beacon.getRssi().toString());
                        System.out.println(beacon.getSerialNumber() + "static");

                    } else if (beacon.getMovingState() == Beacon.MovingState.MOVING) {
                        // Device is moving
                        Log.d("Main", beacon.getSerialNumber() + "moving");
                        Log.d("Main", beacon.getProximityUUID());
                        System.out.println(beacon.getSerialNumber() + "moving");
                    }
                }
            }
        }

        @Override
        public void onNewBeacon(Beacon beacon) {
            // New sensor found
            System.out.println(beacon.getSerialNumber());
            Log.d("Main", beacon.getSerialNumber() + "Got New");
        }

        @Override
        public void onGoneBeacon(Beacon beacon) {
            // A sensor disappears from the range
            System.out.println(beacon.getSerialNumber());

        }
    };
    sensoroManager.setBeaconManagerListener(beaconManagerListener);
}

From source file:com.phonegap.plugins.pdfViewer.PdfViewer.java

public String showPdf(String fileName) {

    File file = new File(fileName);

    if (file.exists()) {
        try {//from  w  ww.  ja  v  a  2 s.  c om
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/pdf");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            //intent.setData(Uri.parse(fileName));
            this.ctx.startActivity(intent);
            return "";
        } catch (android.content.ActivityNotFoundException e) {
            System.out.println("PdfViewer: Error loading url " + fileName + ":" + e.toString());
            return e.toString();
        }

    } else {
        return "file not found";
    }
}