Example usage for android.content Intent addFlags

List of usage examples for android.content Intent addFlags

Introduction

In this page you can find the example usage for android.content Intent addFlags.

Prototype

public @NonNull Intent addFlags(@Flags int flags) 

Source Link

Document

Add additional flags to the intent (or with existing flags value).

Usage

From source file:com.njlabs.amrita.aid.gpms.ui.GpmsActivity.java

private void exitGpms() {
    if (loggedIn) {
        if (backPress + 2000 > System.currentTimeMillis()) {
            toast.cancel();/*from   w w  w.ja v  a 2s  .com*/
            gpms.logout();
            Toast.makeText(getApplicationContext(), "You have successfully logged out.", Toast.LENGTH_LONG)
                    .show();
            Intent intent = new Intent(baseContext, Landing.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        } else {
            toast = Toast.makeText(getBaseContext(), "Press once again to Log Out of GPMS.",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        backPress = System.currentTimeMillis();
    } else {
        Intent intent = new Intent(baseContext, Landing.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }
}

From source file:eu.operando.proxy.OperandoProxyStatus.java

private void reloadActivity() {
    finish();/*from ww  w  . j a  v a  2s  .  co m*/
    Intent intent = new Intent(this, MainProxyActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
            | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:io.selendroid.server.ServerInstrumentation.java

public void resumeActivity() {
    Activity activity = activitiesReporter.getBackgroundActivity();
    Log.d("TAG", "got background activity");
    if (activity == null) {
        SelendroidLogger.error("activity class is empty",
                new NullPointerException("Activity class to start is null."));
        return;//from  www .  ja  v  a  2  s .  c  om
    }
    // start now the new activity
    Log.d("TAG", "background activity is not null");
    Intent intent = new Intent(getTargetContext(), activity.getClass());
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Log.d("TAG", "created intent and got target context");
    getTargetContext().startActivity(intent);
    Log.d("TAG", "got target context and started activity");
    activitiesReporter.setBackgroundActivity(null);
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.MusicObj.java

@Override
public void activate(Context context, SignedObj obj) {
    JSONObject content = obj.getJson();/*from  w  ww. j  a v  a  2s .  co  m*/
    if (content.has(URL)) {
        Intent view = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.parse(content.optString(URL));
        String type = "audio/x-mpegurl";
        if (content.has(MIME_TYPE)) {
            type = content.optString(MIME_TYPE);
        }
        view.setDataAndType(uri, type);
        if (!(context instanceof Activity)) {
            view.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        context.startActivity(view);
    }
}

From source file:com.njlabs.amrita.aid.aums.AumsActivity.java

private void exitAums() {
    if (isLoggedIn) {
        if (backPressTime + 2000 > System.currentTimeMillis()) {
            toast.cancel();//from ww  w .  ja  v  a  2  s. c o m
            aums.logout();
            Toast.makeText(getApplicationContext(), "You have successfully logged out.", Toast.LENGTH_LONG)
                    .show();
            Intent intent = new Intent(baseContext, Landing.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        } else {
            toast = Toast.makeText(getBaseContext(), "Press once again to Log Out of AUMS.",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        backPressTime = System.currentTimeMillis();
    } else {
        Intent intent = new Intent(baseContext, Landing.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }
}

From source file:com.handshake.notifications.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *///from w  ww  .j  av a  2 s.  c  om
private void sendNotification(final Bundle data, long userId, boolean isContact) {
    Intent intent;
    if (userId == 0) {
        intent = new Intent(this, MainActivity.class);
    } else if (isContact) {
        intent = new Intent(this, ContactUserProfileActivity.class);
    } else {
        intent = new Intent(this, GenericUserProfileActivity.class);
    }
    intent.putExtra("userId", userId);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    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("Handshake")
            .setContentText(data.getString("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.krayzk9s.imgurholo.services.UploadService.java

public void onGetObject(Object o, String tag) {
    String id = (String) o;
    if (id.length() == 7) {
        if (totalUpload != -1)
            ids.add(id);/*from  w w w  . j  av a 2 s  . com*/
        if (ids.size() == totalUpload) {
            ids.add(0, ""); //weird hack because imgur eats the first item of the array for some bizarre reason
            NewAlbumAsync newAlbumAsync = new NewAlbumAsync("", "", apiCall, ids, this);
            newAlbumAsync.execute();
        }
    } else if (apiCall.settings.getBoolean("AlbumUpload", true)) {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Intent viewImageIntent = new Intent();
        viewImageIntent.setAction(Intent.ACTION_VIEW);
        viewImageIntent.setData(Uri.parse("http://imgur.com/a/" + id));
        Intent shareIntent = new Intent();
        shareIntent.setType("text/plain");
        shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        shareIntent.putExtra(Intent.EXTRA_TEXT, "http://imgur.com/a/" + id);
        PendingIntent viewImagePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                viewImageIntent, 0);
        PendingIntent sharePendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
                shareIntent, 0);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading Album").setContentTitle("imgur Image Uploader")
                .setContentIntent(viewImagePendingIntent)
                .addAction(R.drawable.dark_social_share, "Share", sharePendingIntent).build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    } else {
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
        Notification notification = notificationBuilder.setSmallIcon(R.drawable.icon_desaturated)
                .setContentText("Finished Uploading All Images").setContentTitle("imgur Image Uploader")
                .build();
        Log.d("Built", "Notification built");
        notificationManager.cancel(0);
        notificationManager.notify(1, notification);
        Log.d("Built", "Notification display");
    }
}

From source file:com.cmgapps.android.util.CMGAppRater.java

/**
 * Shows a default {@link AlertDialog}//from  w w  w  .java2s  .com
 *
 * @param context A Context to show the dialog
 */
public void show(final Context context) {
    if (context == null) {
        throw new IllegalArgumentException("context cannot be null");
    }

    if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
        throw new RuntimeException("CMGAppRater.show() must be called from main thread");
    }

    if (mDialog != null && mDialog.isShowing())
        return;

    final Editor editor = mPref.edit();
    final PackageManager pm = context.getPackageManager();

    String appName;
    try {
        ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);
        appName = (String) pm.getApplicationLabel(ai);
    } catch (NameNotFoundException e) {
        LOGE(TAG, "Application name can not be found");
        appName = "App";
    }

    mDialog = new AlertDialog.Builder(context).setTitle(R.string.dialog_cmgrate_title)
            .setMessage(context.getString(R.string.dialog_cmgrate_message, appName)).setCancelable(false)
            .setIcon(context.getApplicationInfo().icon)
            .setPositiveButton(context.getString(R.string.dialog_cmgrate_ok),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            editor.putBoolean(APP_RATED, true);
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + context.getPackageName()));
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);

                            PreferenceEditorHelper.commit(editor);
                            dialog.dismiss();
                        }
                    })
            .setNegativeButton(R.string.dialog_cmgrate_no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    PreferenceEditorHelper.commit(editor.putBoolean(DECLINED_RATE, true));
                    dialog.dismiss();
                }
            }).setNeutralButton(R.string.dialog_cmgrate_later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    PreferenceEditorHelper
                            .commit(editor.putLong(REMIND_LATER_DATE, System.currentTimeMillis()));
                    dialog.dismiss();
                }
            }).show();
    PreferenceEditorHelper.commit(editor);
}

From source file:fr.cph.stock.android.StockTrackerApp.java

/**
 * This function loads the error activity to the screen. It happens usually when the session is timeout and needs to request a
 * new session id to the server//  w  ww  . j  ava  2 s  .  co m
 * 
 * @param currentActivity
 *            the activity to stop
 * @param jsonObject
 *            the json object containing the error message
 */
public void loadErrorActivity(Activity currentActivity, JSONObject jsonObject) {
    Intent intent = new Intent(this, ErrorActivity.class);
    intent.putExtra("data", jsonObject.toString());
    SharedPreferences settings = getSharedPreferences(BaseActivity.PREFS_NAME, 0);
    String login = settings.getString("login", null);
    String password = settings.getString("password", null);
    intent.putExtra("login", login);
    intent.putExtra("password", password);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    currentActivity.finish();
}

From source file:com.romanenco.gitt.BrowserActivity.java

private void deleteThisRepo() {
    AlertDialog dlg = new AlertDialog.Builder(this).setMessage(R.string.confirm_repo_delete)
            .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    DAO dao = new DAO(BrowserActivity.this);
                    dao.open(true);/*from   www . ja v a2s.c  om*/
                    dao.delete(current.getFolder());
                    dao.close();
                    Intent delete = new Intent(BrowserActivity.this, GitService.class);
                    delete.putExtra(GitService.COMMAND, GitService.Command.Delete);
                    delete.putExtra(GitService.REPO, current);
                    startService(delete);
                    Intent main = new Intent(BrowserActivity.this, MainActivity.class);
                    main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(main);
                }
            }).setNegativeButton(getString(android.R.string.cancel), null).create();
    dlg.setCanceledOnTouchOutside(false);
    dlg.show();
}