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:mobisocial.musubi.objects.PictureObj.java

@Override
public void activate(Context context, DbObj obj) {
    // TODO: set data uri for obj
    Intent intent = new Intent(context, ImageGalleryActivity.class);
    intent.setData(obj.getContainingFeed().getUri());
    intent.putExtra(ImageGalleryActivity.EXTRA_DEFAULT_OBJECT_ID, obj.getLocalId());
    if (!(context instanceof Activity)) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }//from  w  ww.j ava 2s . c om
    context.startActivity(intent);
}

From source file:foundme.uniroma2.it.professore.Connection.java

@Override
protected void onPostExecute(String result[]) {
    if (result[0].equalsIgnoreCase(Variables_it.NO_INTERNET)) {
        if (enProgressDialog)
            caricamento.dismiss();/*from   w w w  .j a v a  2 s  .c  o m*/
        Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
        return;
    }
    if (enProgressDialog) {
        caricamento.dismiss();
        if (!returnMessage.equalsIgnoreCase(Variables_it.NAME)
                || result[0].equalsIgnoreCase(Variables_it.ERROR)) {
            if (!returnMessage.equalsIgnoreCase("") && !returnMessage.equalsIgnoreCase(Variables_it.NO_MSG)) {
                Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
            }
        }
    }
    if (returnMessage.equalsIgnoreCase(Variables_it.NO_MSG)) {
        ReadMessageActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.DEL_MSG_OK)) {
        try {
            ReadMessageActivity.getMsg(toDo, false);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else if (toDo.equalsIgnoreCase(Variables_it.GET)) {
        HomeActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.SEND_MSG_OK)
            && toDo.equalsIgnoreCase(Variables_it.MSGS)) {
        ((Activity) context).finish();
    } else if (returnMessage.equalsIgnoreCase(Variables_it.NAME) && toDo.equalsIgnoreCase(Variables_it.LOG)
            && !result[0].equalsIgnoreCase(Variables_it.ERROR)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, LoginActivity.getuser());
        SPEditor.setPass(pref, LoginActivity.getpass());
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra(Variables_it.TAG, LoginActivity.gettag());
        intent.putExtra(Variables_it.NAME, result[0]);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.FINISH)) {
        ((Activity) context).finish();
        try {
            HomeActivity.getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.CHANGEP)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setPass(pref, ChangePswActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.REGIS)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, RegistrationActivity.getmail());
        SPEditor.setPass(pref, RegistrationActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.DELACC)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.delete(pref);
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }

    else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.HOME)) {
        try {
            HomeActivity.getCourse(false);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:it.uniroma2.foundme.studente.Connection.java

@Override
protected void onPostExecute(String result[]) {
    if (result[0].equalsIgnoreCase(Variables_it.NO_INTERNET)) {
        if (enProgressDialog)
            caricamento.dismiss();//from www. ja  v  a2 s  . c om
        Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
        return;
    }
    if (enProgressDialog) {
        caricamento.dismiss();
        if (!returnMessage.equalsIgnoreCase(Variables_it.NAME)
                || result[0].equalsIgnoreCase(Variables_it.ERROR)) {
            if (!returnMessage.equalsIgnoreCase(Variables_it.SHOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.FOLLOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.UNFOLLOW)
                    && !returnMessage.equalsIgnoreCase(Variables_it.MSG)
                    && !returnMessage.equalsIgnoreCase(Variables_it.MID)) {
                Toast.makeText(context, result[0], Toast.LENGTH_SHORT).show();
            }
        }
    }
    if (toDo.equalsIgnoreCase(Variables_it.GET)) {
        if (returnMessage.equalsIgnoreCase(Variables_it.SHOW))
            ShowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.FOLLOW))
            FollowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.UNFOLLOW))
            UnFollowCourseActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.MSG))
            ReadMessageActivity.populateView(result);
        if (returnMessage.equalsIgnoreCase(Variables_it.MID))
            ShowMsgActivity.populateView(result);
    } else if (returnMessage.equalsIgnoreCase(Variables_it.NAME) && toDo.equalsIgnoreCase(Variables_it.LOG)
            && !result[0].equalsIgnoreCase(Variables_it.ERROR)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, LoginActivity.getuser());
        SPEditor.setPass(pref, LoginActivity.getpass());
        SPEditor.setGCM(pref, result[2]);
        SPEditor.setID(pref, result[1]);
        Intent intent = new Intent(context, HomeActivity.class);
        intent.putExtra(Variables_it.NAME, result[0]);
        intent.putExtra(Variables_it.ID, result[1]);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    } else if (toDo.equalsIgnoreCase(Variables_it.INFOC)) {
        try {
            CourseActivity.setFields(json_data.getString(Variables_it.CFU),
                    json_data.getString(Variables_it.NAME_1), json_data.getString(Variables_it.NAME_2),
                    json_data.getInt(Variables_it.NOTIFICATION));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.CHANGEP)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setPass(pref, ChangePswActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.REGIS)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.setUser(pref, RegistrationActivity.getmail());
        SPEditor.setPass(pref, RegistrationActivity.getpass());
        ((Activity) context).finish();
    } else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.DELACC)) {
        SharedPreferences pref = SPEditor.init(context);
        SPEditor.delete(pref);
        Intent intent = new Intent(context, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        context.startActivity(intent);
    }

    else if (code == 1 && toDo.equalsIgnoreCase(Variables_it.UNFOLLOW)) {
        try {
            UnFollowCourseActivity.getCourse(true);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEvent.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home: {
        finish();/*from   ww w.jav  a2  s .com*/
        return true;
    }

    case R.id.AddLog: {
        addMessageDialog = new Dialog(ViewZenossEvent.this);
        addMessageDialog.setContentView(R.layout.add_message);
        addMessageDialog.setTitle("Add Message to Event Log");
        ((Button) addMessageDialog.findViewById(R.id.SaveButton)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                AddLogMessage(((EditText) addMessageDialog.findViewById(R.id.LogMessage)).getText().toString());
                addMessageDialog.dismiss();
            }
        });

        addMessageDialog.show();
        return true;
    }

    case R.id.escalate: {
        Intent intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

        // Add data to the intent, the receiving app will decide what to do with it.
        intent.putExtra(Intent.EXTRA_SUBJECT,
                "Escalation of Zenoss Event on " + getIntent().getStringExtra("Device"));
        String EventDetails = getIntent().getStringExtra("Summary") + "\r\r\n"
                + getIntent().getStringExtra("LastTime") + "\r\r\n" + "Count: "
                + getIntent().getIntExtra("Count", 0);

        intent.putExtra(Intent.EXTRA_TEXT, EventDetails);

        startActivity(Intent.createChooser(intent, "How would you like to escalate this event?"));
    }

    default: {
        return false;
    }
    }
}

From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesActivity.java

private void createShortcut() {
    Intent shortcutIntent = new Intent(this, PreferencesActivity.class);
    shortcutIntent.putExtra(EXTRA_PACKAGE_NAME, packageName);
    shortcutIntent.putExtra(EXTRA_TITLE, title);
    shortcutIntent.putExtra(EXTRA_SHORTCUT, true);
    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, title);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    addIntent.setAction(INSTALL_SHORTCUT);
    sendBroadcast(addIntent);/* ww w.  j a  va 2s.  com*/
}

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:com.alphabetbloc.accessmrs.services.SyncAdapter.java

private void performSync(SyncResult syncResult) {
    mTimeoutException = null;/*from  w  ww  . j  a v a  2s.  c  o  m*/
    HttpClient client = NetworkUtils.getHttpClient();
    if (client == null) {
        // ++syncResult.stats.numIoExceptions;
        Log.e(TAG, "HttpClient is null!  Check the credential storage!");
        Intent i = new Intent(mContext, LauncherActivity.class);
        i.putExtra(LauncherActivity.LAUNCH_DASHBOARD, false);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(i);
        UiUtils.toastAlert(mContext.getString(R.string.sync_error), mContext.getString(R.string.no_connection));
        return;
    }
    // UPLOAD FORMS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms), false); // 0%
    String[] instancesToUpload = mSyncManager.getInstancesToUpload();
    String[] instancesUploaded = uploadInstances(client, instancesToUpload, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms),
            (instancesUploaded.length < 1) ? true : false); // 10%
    String dbError = mSyncManager.updateUploadedForms(instancesUploaded, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_uploading_forms),
            (instancesUploaded.length < 1) ? true : false); // 20%
    int uploadErrors = (int) syncResult.stats.numIoExceptions;
    mSyncManager.toastSyncUpdate(SyncManager.UPLOAD_FORMS, instancesUploaded.length, instancesToUpload.length,
            uploadErrors, dbError);
    if (App.DEBUG)
        Log.v(TAG, "End of Upload ConnectionTimeOutException=" + mTimeoutException);
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }

    // DOWNLOAD NEW FORMS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms), false); // No
    // Change
    Form[] formsToDownload = findNewFormsOnServer(client, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsToDownload.length < 1) ? true : false); // 30%
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }
    Form[] formsDownloaded = downloadNewForms(client, formsToDownload, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsDownloaded.length < 1) ? true : false); // 40%
    dbError = mSyncManager.updateDownloadedForms(formsDownloaded, syncResult);
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_forms),
            (formsDownloaded.length < 1) ? true : false); // 50%
    if (App.DEBUG)
        Log.v(TAG, "Downloaded New Forms with result errors=" + syncResult.stats.numIoExceptions);
    int downloadErrors = ((int) syncResult.stats.numIoExceptions) - uploadErrors;
    mSyncManager.toastSyncUpdate(SyncManager.DOWNLOAD_FORMS, formsDownloaded.length, formsToDownload.length,
            downloadErrors, dbError);
    if (mTimeoutException != null) {
        mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, mTimeoutException);
        return;
    }

    // DOWNLOAD NEW OBS
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_downloading_data), false); // No
    // Change
    long before = System.currentTimeMillis();
    File temp = downloadObsStream(client, syncResult);
    if (App.DEBUG)
        Log.v("SYNC BENCHMARK",
                "Download Time: \n" + sTimeLog.format(new Date(System.currentTimeMillis() - before)));
    mSyncManager.addSyncStep(mContext.getString(R.string.sync_updating_data), true); // 60%
    if (temp != null) {
        dbError = mSyncManager.readObsFile(temp, syncResult); // 70-100%
        FileUtils.deleteFile(temp.getAbsolutePath());
    }
    int downloadObsErrors = ((int) syncResult.stats.numIoExceptions) - (uploadErrors + downloadErrors);
    mSyncManager.toastSyncUpdate(SyncManager.DOWNLOAD_OBS, -1, -1, downloadObsErrors, dbError);
    if (App.DEBUG)
        Log.v(TAG, "Downloaded New Obs with result errors=" + syncResult.stats.numIoExceptions);

    // TOAST RESULT
    mSyncManager.toastSyncResult((int) syncResult.stats.numIoExceptions, null);

}

From source file:de.lespace.apprtc.firebase.MyFirebaseMessagingService.java

/**
 * Called when message is received./*  w  w w  . ja v  a  2s . c  o m*/
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {

    JSONObject jsonData = new JSONObject(remoteMessage.getData());
    Log.d(TAG, "calldata: " + jsonData.toString());

    Intent intent = new Intent(this, SignalingService.class);
    intent.putExtra(RTCConnection.EXTRA_SIGNALING_REGISTRATION, "true");
    intent.putExtra(RTCConnection.EXTRA_FROM, remoteMessage.getData().get("toUUID"));
    startService(intent);

    //Start Registration
    Log.d(TAG, "we should call to:" + remoteMessage.getData().get("fromUUID") + " but callto 'chrome' now!");
    Intent connectIntent = new Intent(getApplicationContext(), IncomingCall.class);
    String to = "chrome";
    RTCConnection.from = remoteMessage.getData().get("toUUID");
    RTCConnection.to = to;
    RTCConnection.initiator = true;
    /*
    connectIntent.putExtra(RTCConnection.EXTRA_TO, to);
    connectIntent.putExtra(RTCConnection.EXTRA_FROM, remoteMessage.getData().get("toUUID"));
    connectIntent.putExtra(RTCConnection.EXTRA_INITIATOR, true);*/
    connectIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(connectIntent);

}

From source file:me.piebridge.prevent.ui.UserGuideActivity.java

private boolean donateViaAlipay() {
    showDonateDialog();/*from w  w  w .j  a v a  2 s . c om*/
    Intent intent = new Intent();
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(BuildConfig.DONATE_ALIPAY));
    try {
        startActivity(intent);
    } catch (Throwable t) { // NOSONAR
        hideDonateDialog();
    }
    return true;
}

From source file:com.petrodevelopment.dice.external.Router.java

private void addFlagsToIntent(Intent intent, Context context) {
    if (context == this._context) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }/*from  w w  w .jav a2 s .c  om*/
}