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:co.touchlab.thumbcache.ui.ImageDetailActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // Home or "up" navigation
        final Intent intent = new Intent(this, ImageGridActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);/*from   ww  w . j a v a  2s  .com*/
        return true;
    case R.id.clear_cache:
        final ImageCache cache = mImageWorker.getImageCache();
        if (cache != null) {
            mImageWorker.getImageCache().clearCaches();
            //DiskLruCache.clearCache(this, ImageFetcher.HTTP_CACHE_DIR);
            Toast.makeText(this, R.string.clear_cache_complete, Toast.LENGTH_SHORT).show();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.bayapps.android.robophish.ui.MusicPlayerActivity.java

private void startFullScreenActivityIfNeeded(Intent intent) {
    if (intent != null && intent.getBooleanExtra(EXTRA_START_FULLSCREEN, false)) {
        Intent fullScreenIntent = new Intent(this, FullScreenPlayerActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP)
                .putExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION,
                        intent.getParcelableExtra(EXTRA_CURRENT_MEDIA_DESCRIPTION));
        startActivity(fullScreenIntent);
    }//from   w w  w  . j av  a 2 s.c  o  m
}

From source file:android.example.com.squawker.fcm.SquawkFirebaseMessageService.java

/**
 * Create and show a simple notification containing the received FCM message
 *
 * @param data Map which has the message data in it
 *//*from  w  ww  .  j av  a  2s. c  o  m*/
private void sendNotification(Map<String, String> data) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Create the pending intent to launch the activity
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String author = data.get(JSON_KEY_AUTHOR);
    String message = data.get(JSON_KEY_MESSAGE);

    // If the message is longer than the max number of characters we want in our
    // notification, truncate it and add the unicode character for ellipsis
    if (message.length() > NOTIFICATION_MAX_CHARACTERS) {
        message = message.substring(0, NOTIFICATION_MAX_CHARACTERS) + "\u2026";
    }

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_duck)
            .setContentTitle(String.format(getString(R.string.notification_message), author))
            .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.app.infideap.postingapp.service.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *//*  ww w .jav a2s .  co  m*/
private void sendNotification(RemoteMessage remoteMessage) {
    //        Toast.makeText(getApplication(), "Received", Toast.LENGTH_SHORT).show();
    Notification notification = null;
    if (remoteMessage.getData() != null)
        notification = saveData(remoteMessage);
    else if (remoteMessage.getNotification() != null)
        notification = save(remoteMessage);

    if (notification == null)
        return;

    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_launcher).setContentTitle(notification.title)
            .setContentText(notification.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:io.github.pwlin.cordova.plugins.fileopener2.FileOpener2.java

private void _open(String fileArg, String contentType, CallbackContext callbackContext) throws JSONException {
    String fileName = "";
    try {//from  w  w  w. j a  va 2 s . c o m
        CordovaResourceApi resourceApi = webView.getResourceApi();
        Uri fileUri = resourceApi.remapUri(Uri.parse(fileArg));
        fileName = this.stripFileProtocol(fileUri.toString());
    } catch (Exception e) {
        fileName = fileArg;
    }
    File file = new File(fileName);
    if (file.exists()) {
        try {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            if (Build.VERSION.SDK_INT >= 24) {

                Context context = cordova.getActivity().getApplicationContext();
                path = FileProvider.getUriForFile(context,
                        cordova.getActivity().getPackageName() + ".opener.provider", file);
                intent.setDataAndType(path, contentType);
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                List<ResolveInfo> infoList = context.getPackageManager().queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : infoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    context.grantUriPermission(packageName, path,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            } else {
                intent.setDataAndType(path, contentType);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            }
            /*
             * @see
             * http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
             */
            cordova.getActivity().startActivity(intent);
            //cordova.getActivity().startActivity(Intent.createChooser(intent,"Open File in..."));
            callbackContext.success();
        } catch (android.content.ActivityNotFoundException e) {
            JSONObject errorObj = new JSONObject();
            errorObj.put("status", PluginResult.Status.ERROR.ordinal());
            errorObj.put("message", "Activity not found: " + e.getMessage());
            callbackContext.error(errorObj);
        }
    } else {
        JSONObject errorObj = new JSONObject();
        errorObj.put("status", PluginResult.Status.ERROR.ordinal());
        errorObj.put("message", "File not found");
        callbackContext.error(errorObj);
    }
}

From source file:com.android.emergency.view.ViewInfoActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();//from  w w  w  . j a  v  a 2 s .c o  m
        return true;

    case R.id.action_edit:
        Intent intent = new Intent(this, EditInfoActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.actionbarsherlock.sample.hcgallery.CameraFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.switch_cam:
        // Release this camera -> mCameraCurrentlyLocked
        if (mCamera != null) {
            mCamera.stopPreview();//from  w w w  .  j av  a2  s.  c  o  m
            mPreview.setCamera(null);
            mCamera.release();
            mCamera = null;
        }

        // Acquire the next camera and request Preview to reconfigure
        // parameters.
        mCamera = Camera.open((mCameraCurrentlyLocked + 1) % mNumberOfCameras);
        mCameraCurrentlyLocked = (mCameraCurrentlyLocked + 1) % mNumberOfCameras;
        mPreview.switchCamera(mCamera);

        // Start the preview
        mCamera.startPreview();
        return true;
    case android.R.id.home:
        Intent intent = new Intent(this.getActivity(), MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(intent);

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.barcodeeye.scan.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_capture);

    context2 = this;
    StringBuilder loginData = new StringBuilder();
    try {//from ww w.j a  v  a2s .  c o  m

        File f = new File(getCacheDir(), "LoginData.txt");
        if (f.exists()) {
            BufferedReader br = new BufferedReader(new FileReader(f));
            String line;

            while ((line = br.readLine()) != null) {
                loginData.append(line);
            }

            if (!loginData.toString().isEmpty()) {
                System.out.println("!!!!!!" + loginData.toString() + "!!!!!!!");
                // Intent Creation and Initialization
                Intent intent = new Intent(context2, InformationPreviewActivity.class);
                //I have added the line: (flags) (for closing the first activity)
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                // Create a Bundle and Put Bundle into it (SENDS PERSON)
                Bundle bundleObject = new Bundle();
                bundleObject.putSerializable("key", loginData.toString());
                // Put Bundle into Intent and call start Activity
                intent.putExtras(bundleObject);
                startActivity(intent);
                //I have added the line: (finish) (for closing the first activity)
                finish();
            }
        }
    } catch (IOException e) {
        //You'll need to add proper error handling here
    }

    mImageManager = new ImageManager(this);

    mHasSurface = false;
    mInactivityTimer = new InactivityTimer(this);
    mBeepManager = new BeepManager(this);
    mAmbientLightManager = new AmbientLightManager(this);

    mViewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);

    if (loginData.toString().isEmpty()) {
        Toast.makeText(getApplicationContext(), "Scan QR code for Login", Toast.LENGTH_LONG).show();
    }

    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
}

From source file:com.meetingninja.csse.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SessionManager.getInstance().init(MainActivity.this);
    session = SessionManager.getInstance();

    // Check if logged in
    if (!session.isLoggedIn()) {
        Log.v(TAG, "User is not logged in");
        Intent login = new Intent(this, LoginActivity.class);
        // Bring login to front
        login.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        // User cannot go back to this activity
        // login.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        // Show no animation when launching login page
        login.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(login);/*from  ww  w.jav  a  2s  .  c  o m*/
        finish(); // close main activity
    } else { // Else continue
        Log.v(TAG, "UserID " + session.getUserID() + " is logged in");
        setContentView(R.layout.activity_main);
        setupActionBar();
        setupViews();

        // on first time display view for first nav item
        selectItem(session.getPage());

        // Check to see if data has been cached in the local database
        if (savedInstanceState != null) {
            isDataCached = savedInstanceState.getBoolean(KEY_SQL_CACHE, false);
        }
        if (!isDataCached && session.needsSync()) {
            ApplicationController.getInstance().loadUsers();
            isDataCached = true;
            session.setSynced();
        }

        // Track the usage of the application with Parse SDK
        ParseAnalytics.trackAppOpened(getIntent());
        ParseUser parseUser = ParseUser.getCurrentUser();
        if (parseUser != null) {
            ParseInstallation installation = ParseInstallation.getCurrentInstallation();
            installation.put("user", parseUser);
            installation.put("userId", parseUser.getObjectId());
            installation.saveEventually();
        }
    }

}