Example usage for android.content Intent setFlags

List of usage examples for android.content Intent setFlags

Introduction

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

Prototype

public @NonNull Intent setFlags(@Flags int flags) 

Source Link

Document

Set special flags controlling how this intent is handled.

Usage

From source file:com.codebutler.farebot.activities.AddKeyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_key);
    getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT);

    findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
        @Override//from   ww  w .  java2 s .c om
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final String keyType = ((RadioButton) findViewById(R.id.is_key_a)).isChecked()
                    ? ClassicSectorKey.TYPE_KEYA
                    : ClassicSectorKey.TYPE_KEYB;

            new BetterAsyncTask<Void>(AddKeyActivity.this, true, false) {
                @Override
                protected Void doInBackground() throws Exception {
                    ClassicCardKeys keys = ClassicCardKeys.fromDump(keyType, mKeyData);

                    ContentValues values = new ContentValues();
                    values.put(KeysTableColumns.CARD_ID, mTagId);
                    values.put(KeysTableColumns.CARD_TYPE, mCardType);
                    values.put(KeysTableColumns.KEY_DATA, keys.toJSON().toString());

                    getContentResolver().insert(CardKeyProvider.CONTENT_URI, values);

                    return null;
                }

                @Override
                protected void onResult(Void unused) {
                    Intent intent = new Intent(AddKeyActivity.this, KeysActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    finish();
                }
            }.execute();
        }
    });

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    Utils.checkNfcEnabled(this, mNfcAdapter);

    Intent intent = getIntent();
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

    if (getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_VIEW)
            && getIntent().getData() != null) {
        try {
            InputStream stream = getContentResolver().openInputStream(getIntent().getData());
            mKeyData = IOUtils.toByteArray(stream);
        } catch (IOException e) {
            Utils.showErrorAndFinish(this, e);
        }
    } else {
        finish();
    }
}

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

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra("android.intent.extra.APPLICATION_ARGUMENT", arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String webUrl = obj.optString(WEB_URL);
    launch.setData(Uri.parse(webUrl));/*from  ww w.  j  a va 2  s  . c  o m*/
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received",
            "Click to launch application.", contentIntent);
}

From source file:samples.piggate.com.piggateCompleteExample.Activity_Exchange.java

public void goBackActivity(boolean exchanged) {
    //Go back to the offer list passing the offer attributes (to exchange)
    Intent slideactivity = new Intent(Activity_Exchange.this, Activity_Logged.class);
    slideactivity.putExtra("exchanged", exchanged);
    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    Bundle bndlanimation = ActivityOptions
            .makeCustomAnimation(getApplicationContext(), R.anim.slidefromleft, R.anim.slidetoright).toBundle();
    startActivity(slideactivity, bndlanimation);
}

From source file:com.mycelium.wallet.simplex.SimplexMainActivity.java

@Override
protected void onResume() {
    super.onResume();

    // Register ourselves so that we can provide the initial value.
    _eventBus.register(this);

    if (this._simplexUIType == SimplexUITypes.WebView) {
        Log.d("simplex", "onResume WebView");
        Intent i = new Intent(SimplexMainActivity.this, ModernMain.class);
        i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);/*w  w  w  .j a v  a2 s .  c om*/
    }
}

From source file:samples.piggate.com.piggateInfoDemo.InfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artwork);

    //Set action bar fields
    getSupportActionBar().setTitle(PiggateUser.getEmail());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    title = (TextView) findViewById(R.id.InfoTitle);
    description = (TextView) findViewById(R.id.InfoDescription);
    image = (SmartImageView) findViewById(R.id.InfoImage);
    videoButton = (FloatingActionButton) findViewById(R.id.videoButton);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Logout error");
    errorDialog.setMessage("There is an error with the logout");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*from  w  w  w. j  a  v a 2  s  .co m*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    title.setText(getIntent().getExtras().getString("infoTitle"));
    description.setText(getIntent().getExtras().getString("infoDescription"));
    image.setImageUrl(getIntent().getExtras().getString("infoImageURL"));

    videoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (checkInternetConnection() == true) { //If internet is working

                //Start the video here
                Intent slideactivity = new Intent(getApplicationContext(), VideoViewActivity.class);
                slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                //Information about selected content
                slideactivity.putExtra("infoTitle", getIntent().getExtras().getString("infoTitle"));
                slideactivity.putExtra("infoDescription", getIntent().getExtras().getString("infoDescription"));
                slideactivity.putExtra("infoImageURL", getIntent().getExtras().getString("infoImageURL"));
                slideactivity.putExtra("infoVideoURL", getIntent().getExtras().getString("infoVideoURL"));
                Bundle bndlanimation = ActivityOptions
                        .makeCustomAnimation(getApplicationContext(), R.anim.slidefromright, R.anim.slidetoleft)
                        .toBundle();
                getApplicationContext().startActivity(slideactivity, bndlanimation);
            } else {
                //If internet conexion is not working displays an error message
                networkErrorDialog.show();
            }
        }
    });
}

From source file:com.gh4a.BlogListActivity.java

@Override
public boolean setMenuOptionItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        if (!isAuthorized()) {
            Intent intent = new Intent().setClass(this, Github4AndroidActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);/*from  w  ww .  ja  va 2  s.c  o m*/
            finish();
        } else {
            getApplicationContext().openUserInfoActivity(this, getAuthLogin(), null,
                    Intent.FLAG_ACTIVITY_CLEAR_TOP);
            return true;
        }
    case R.id.pub_timeline:
        Intent intent = new Intent().setClass(this, TimelineActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    case R.id.trend:
        intent = new Intent().setClass(this, TrendingActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        return true;
    default:
        return true;
    }
}

From source file:com.memetro.android.oauth.OAuth.java

public JSONObject call(String controller, String action, Map<String, String> params) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(oauthServer + controller + "/" + action);

    try {/*from  w  w  w . ja  v  a 2  s  .c  om*/
        // Add data
        httppost.setEntity(new UrlEncodedFormEntity(Map2NameValuePair(params)));

        // Execute Post
        HttpResponse response = httpclient.execute(httppost);

        // Catch headers
        int statusCode = response.getStatusLine().getStatusCode();
        lastHttpStatus = statusCode;
        if (statusCode != 200) {
            JSONObject returnJ = new JSONObject();
            returnJ.put("success", false);
            returnJ.put("data", new JSONArray());

            Log.d("Http Status Code", String.valueOf(statusCode));

            switch (statusCode) {
            case 401:
                if (refreshToken() && firstAuthCall) {
                    firstAuthCall = false;
                    Utils utils = new Utils();
                    params.put("access_token", utils.getToken(context));
                    return call(controller, action, params);
                }

                returnJ.put("message", context.getString(R.string.session_expired));
                Utils utils = new Utils();
                utils.setToken(context, "", "");
                Intent intent = new Intent(context, MainActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                return returnJ;
            case 404:
                returnJ.put("message", context.getString(R.string.action_not_found));
                return returnJ;
            case 500:
                returnJ.put("message", context.getString(R.string.server_error));
                return returnJ;
            default:
                returnJ.put("message", context.getString(R.string.internal_error));
                return returnJ;
            }
        }

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String json = reader.readLine();
        JSONTokener tokener = new JSONTokener(json);

        return new JSONObject(tokener);

    } catch (ClientProtocolException e) {

        // TODO Auto-generated catch block

    } catch (JSONException e) {

        // TODO Auto-generated catch block

    } catch (IOException e) {

        // TODO Auto-generated catch block
    }
    return new JSONObject();
}

From source file:com.android.prachat.gcm.MyGcmPushReceiver.java

/**
 * Showing notification with text only//from   w  w w  .j a v  a2 s . co m
 * */
private void showNotificationMessage(Context context, String title, String message, String timeStamp,
        Intent intent) {
    notificationUtils = new NotificationUtils(context);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
}

From source file:edu.cmu.cs.quiltview.RequestPullingService.java

private void recordForQuery(String query, int queryID, int userID, String imagePath) {
    Intent respondIntent = new Intent(this, RespondActivity.class);
    respondIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    respondIntent.putExtra(RESPOND_INTENT_QUERY, query);
    respondIntent.putExtra(RESPOND_INTENT_QUERY_ID, queryID);
    respondIntent.putExtra(RESPOND_INTENT_USER_ID, userID);
    respondIntent.putExtra(RESPOND_INTENT_QUERY_IMAGE, imagePath);
    startActivity(respondIntent);//from  w ww.j a v a2s  .co  m
}

From source file:com.diusrex.toforeground.ToForeground.java

public boolean execute(String className, JSONArray args, CallbackContext callbackContext) throws JSONException {
    try {/*from   ww  w  .  j  a v  a2s  .c  o  m*/
        Intent it = new Intent("android.intent.action.MAIN");

        String packageName = args.getString(0);

        Activity activity = this.cordova.getActivity();
        it.setComponent(new ComponentName(packageName, packageName + "." + className));
        it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        Context context = activity.getApplicationContext();
        context.startActivity(it);
    } catch (Exception e) {
        return false;
    }
    return true;
}