Example usage for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

List of usage examples for android.content Intent FLAG_ACTIVITY_CLEAR_TASK

Introduction

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

Prototype

int FLAG_ACTIVITY_CLEAR_TASK

To view the source code for android.content Intent FLAG_ACTIVITY_CLEAR_TASK.

Click Source Link

Document

If set in an Intent passed to Context#startActivity Context.startActivity() , this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.

Usage

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

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object
    setContentView(R.layout.activity_logged);
    getSupportActionBar().setTitle(PiggateUser.getEmail());

    startService(new Intent(getApplicationContext(), Service_Notify.class)); //Start the service

    //Initialize and set all the left navigation drawer fields
    mDrawer = new Drawer().withActivity(this).withTranslucentStatusBar(false).withHeader(R.layout.drawerheader)
            .addDrawerItems( /* Add drawer items with this method */)
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override/*w  w  w  .ja  v a 2  s  .c  om*/
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {
                    // Open the exchange activity for the selected item
                    Intent slideactivity = new Intent(Activity_Logged.this, Activity_Exchange.class);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

                    //Send the current offer information to the exchange activity
                    slideactivity.putExtra("offerName", exchangeOfferList.get(position).getName().toString());
                    slideactivity.putExtra("offerDescription",
                            exchangeOfferList.get(position).getDescription().toString());
                    slideactivity.putExtra("offerImgURL",
                            exchangeOfferList.get(position).getImgURL().toString());
                    slideactivity.putExtra("exchangeID",
                            exchangeOfferList.get(position).getExchangeID().toString());

                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(Activity_Logged.this,
                            R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }
            }).withSliderBackgroundColor(Color.parseColor("#FFFFFF")).withSelectedItem(-1).build();

    //Initialize recycler view
    mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(Activity_Logged.this));
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    newBeaconsLayout = (LinearLayout) findViewById(R.id.newBeaconsLayout);

    //Initialize swipe layout
    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mSwipeLayout.setOnRefreshListener(this);

    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
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successPaymentDialog = new AlertDialog.Builder(this).create();
    successPaymentDialog.setTitle("Successful payment");
    successPaymentDialog.setMessage("Now you can exchange your purchased product");
    successPaymentDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorBuyDialog = new AlertDialog.Builder(this).create();
    errorBuyDialog.setTitle("Payment failed");
    errorBuyDialog.setMessage("There is an error with your payment");
    errorBuyDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    successExchangeDialog = new AlertDialog.Builder(this).create();
    successExchangeDialog.setTitle("Offer successfully exchanged");
    successExchangeDialog.setMessage("The offer has been purchased and exchanged");
    successExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    errorExchangeDialog = new AlertDialog.Builder(this).create();
    errorExchangeDialog.setTitle("Exchange error");
    errorExchangeDialog.setMessage("There is an error with the exchange");
    errorExchangeDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        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();
        }
    });

    fadeIn = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadein);
    fadeOut = AnimationUtils.loadAnimation(Activity_Logged.this, R.anim.fadeout);

    //Check if the bluetooth is switched on
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    if (getIntent().hasExtra("payment")) {
        if (getIntent().getExtras().getBoolean("payment") == true) {
            successPaymentDialog.show(); //Show success payment dialog
            mDrawer.openDrawer(); //Open the left panel
        } else {
            errorBuyDialog.show(); //Show payment error dialog
        }
    } else if (getIntent().hasExtra("exchanged")) {
        if (getIntent().getExtras().getBoolean("exchanged") == true) {
            successExchangeDialog.show(); //Show exchange success dialog
        } else {
            errorExchangeDialog.show(); //Show exchange error dialog
        }
    }
}

From source file:edu.Groove9.TunesMaster.playlist.PlaylistActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  ww w. j  a  v  a  2  s  .  c o m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                // Do nothing, we're already on that screen
                break;
            case R.id.statistics_navigation_menu_item:
                Intent statisticsIntent = new Intent(PlaylistActivity.this, StatisticsActivity.class);
                statisticsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(statisticsIntent);
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Login");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_login);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button login = (Button) findViewById(R.id.buttonlogin);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*from ww w  . j a  v  a  2  s. c om*/
        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();
        }
    });

    //OnClick listener for the login button
    //Handles the login request to the server with the email and password fields
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing In", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the login into the application with the user email and password
                    _piggate.RequestOpenSession(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingIn.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

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.wso2.mobile.mdm.services.PolicyTester.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public PolicyTester(Context context, JSONArray recJArray, int type, String msgID) {
    this.context = context;
    devicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    appList = new ApplicationManager(context);
    deviceInfo = new DeviceInfo(context);
    deviceState = new PhoneState(context);

    if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_RETURN) {
        IS_ENFORCE = false;/*from   w w w. java  2s  . c om*/
    } else if (type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) {
        IS_ENFORCE = false;
    } else if (type == POLICY_MONITOR_TYPE_ENFORCE_RETURN) {
        IS_ENFORCE = true;
    } else {
        IS_ENFORCE = false;
        type = POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN;
    }

    SharedPreferences mainPref = context.getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
    policy = mainPref.getString("policy", "");

    try {
        JSONArray jArray = null;
        if (recJArray != null) {
            jArray = recJArray;
        } else {
            jArray = new JSONArray(policy);
        }
        Log.e("POLICY ARAY : ", jArray.toString());
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject policyObj = (JSONObject) jArray.getJSONObject(i);
            if (policyObj.getString("data") != null && policyObj.getString("data") != "") {
                testPolicy(policyObj.getString("code"), policyObj.getString("data"));
            }
        }

        JSONObject rootObj = new JSONObject();
        try {
            if (deviceInfo.isRooted()) {
                rootObj.put("status", false);
            } else {
                rootObj.put("status", true);
            }
            rootObj.put("code", "notrooted");
            finalArray.put(rootObj);
        } catch (JSONException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        Log.e("MONITOR POLICY : ", policy);
        Log.e("MONITOR USER MESSAGE : ", usermessage);
        //Display an alert to the user about policy violation
        if (policy != null && policy != "") {
            if (usermessage != null && usermessage != ""
                    && type == POLICY_MONITOR_TYPE_NO_ENFORCE_MESSAGE_RETURN) {
                Intent intent = new Intent(context, AlertActivity.class);
                intent.putExtra("message", usermessage);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
        }

        returnJSON.put("code", CommonUtilities.OPERATION_POLICY_MONITOR);
        returnJSON.put("data", finalArray);

        Map<String, String> params = new HashMap<String, String>();
        params.put("code", CommonUtilities.OPERATION_POLICY_MONITOR);
        params.put("msgID", msgID);
        params.put("status", "200");
        params.put("data", finalArray.toString());

        ServerUtilities.pushData(params, context);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.rsamadhan.MainActivity.java

private void navigateToLanguageChange() {
    PreferenceManager pref = PreferenceManager.getInstance(this);
    pref.putFirstTimeLogin(true);//from w  ww . j  a v  a  2s  . c  o  m
    Intent intent = new Intent(this, LanguageSelectionActivity.class);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
    finish();
}

From source file:com.silentcircle.contacts.activities.ScContactDetailActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    if (PhoneCapabilityTester.isUsingTwoPanes(this)) {
        // This activity must not be shown. We have to select the contact in the
        // PeopleActivity instead ==> Create a forward intent and finish
        final Intent originalIntent = getIntent();
        Intent intent = new Intent();
        intent.setAction(originalIntent.getAction());
        intent.setDataAndType(originalIntent.getData(), originalIntent.getType());

        // If we are launched from the outside, we should create a new task, because the user
        // can freely navigate the app (this is different from phones, where only the UP button
        // kicks the user into the full app)
        if (NavUtils.shouldUpRecreateTask(this, intent)) {
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                    | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        } else {/*from   w ww  .  ja  v  a  2  s.c o  m*/
            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_FORWARD_RESULT
                    | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }

        intent.setClass(this, ScContactsMainActivity.class);
        startActivity(intent);
        finish();
        return;
    }

    setContentView(R.layout.contact_detail_activity);

    mContactDetailLayoutController = new ContactDetailLayoutController(this, savedState,
            getSupportFragmentManager(), null, findViewById(R.id.contact_detail_container),
            mContactDetailFragmentListener);

    // We want the UP affordance but no app icon.
    // Setting HOME_AS_UP, SHOW_TITLE and clearing SHOW_HOME does the trick.
    ActionBar actionBar = this.getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE,
                ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME);
        actionBar.setTitle("");
    }

    Log.i(TAG, getIntent().getData().toString());
}

From source file:im.vector.receiver.VectorUniversalLinkReceiver.java

@Override
public void onReceive(final Context aContext, final Intent aIntent) {
    String action, uriString;/*from  ww  w.j a v  a2 s . c  om*/
    Uri intentUri;

    Log.d(LOG_TAG, "## onReceive() IN");

    // get session
    mSession = Matrix.getInstance(aContext).getDefaultSession();

    // user is not yet logged in
    if (null == mSession) {
        Log.e(LOG_TAG, "## onReceive() Warning - Unable to proceed URL link: Session is null");

        // No user is logged => no session. Just forward request to the login activity
        Intent intent = new Intent(aContext, LoginActivity.class);
        intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        aContext.startActivity(intent);
        return;
    }

    // sanity check
    if (null != aIntent) {

        action = aIntent.getAction();
        uriString = aIntent.getDataString();
        boolean isSessionActive = mSession.isAlive();
        boolean isLoginStepDone = mSession.getDataHandler().isInitialSyncComplete();

        Log.d(LOG_TAG, "## onReceive() uri getDataString=" + uriString + "isSessionActive=" + isSessionActive
                + " isLoginStepDone=" + isLoginStepDone);

        if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK)) {
            Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK");
            intentUri = aIntent.getData();

        } else if (TextUtils.equals(action, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME)) {
            Log.d(LOG_TAG, "## onReceive() action = BROADCAST_ACTION_UNIVERSAL_LINK_RESUME");

            // A first BROADCAST_ACTION_UNIVERSAL_LINK has been received with a room alias that could not be translated to a room ID.
            // Translation has been asked to server, and the response is processed here.
            // ......................
            intentUri = aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_URI);
            // aIntent.getParcelableExtra(EXTRA_UNIVERSAL_LINK_SENDER_ID);
        } else {
            // unknown action (very unlikely)
            Log.e(LOG_TAG,
                    "## onReceive() Unknown action received (" + action + ") - unable to proceed URL link");
            return;
        }

        if (null != intentUri) {
            Log.d(LOG_TAG, "## onCreate() intentUri - host=" + intentUri.getHost() + " path="
                    + intentUri.getPath() + " queryParams=" + intentUri.getQuery());
            //intentUri.getEncodedSchemeSpecificPart() = //vector.im/beta/  intentUri.getSchemeSpecificPart() = //vector.im/beta/

            HashMap<String, String> params = parseUniversalLink(intentUri);

            if (null != params) {

                if (!isSessionActive) {
                    Log.w(LOG_TAG, "## onReceive() Warning: Session is not alive");
                }

                if (!isLoginStepDone) {
                    Log.w(LOG_TAG, "## onReceive() Warning: Session is not complete - start Login Activity");

                    // Start the login activity and wait for BROADCAST_ACTION_UNIVERSAL_LINK_RESUME.
                    // Once the login process flow is complete, BROADCAST_ACTION_UNIVERSAL_LINK_RESUME is
                    // sent back to resume the URL link processing.
                    Intent intent = new Intent(aContext, LoginActivity.class);
                    intent.putExtra(EXTRA_UNIVERSAL_LINK_URI, aIntent.getData());
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    aContext.startActivity(intent);
                } else {
                    mParameters = params;

                    if (mParameters.containsKey(ULINK_ROOM_ID_OR_ALIAS_KEY)) {
                        manageRoomOnActivity(aContext);
                    } else if (mParameters.containsKey(ULINK_MATRIX_USER_ID_KEY)) {
                        manageMemberDetailsActivity(aContext);
                    } else if (mParameters.containsKey(ULINK_GROUP_ID_KEY)) {
                        manageGroupDetailsActivity(aContext);
                    } else {
                        Log.e(LOG_TAG, "## onReceive() : nothing to do");
                    }
                }
            } else {
                Log.e(LOG_TAG, "## onReceive() Path not supported: " + intentUri.getPath());
            }
        }
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Register");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_register);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button register = (Button) findViewById(R.id.buttonregister);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override//from w  ww .  ja  va  2  s  .c om
        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();
        }
    });

    //OnClick listener for the login button
    //Handles the register request to the server with the email and password fields
    //and the login request if the fields are correct
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing Up", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the register into the application
                    // and the login with the user email and password
                    _piggate.RequestNewUser(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingUp.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:id.satusatudua.sigap.ui.AddTrustedUserActivity.java

@OnClick(R.id.button_save)
public void save() {
    if (adapter.getData().size() < 3) {
        showError("Anda harus memasukan minimal 3 kontak!");
    } else if (!allAccepted()) {
        showError("Akun yang mengkonfirmasi belum sampai 3!");
    } else {//from w  w  w  . j a  v a2s.  c  o m
        new AlertDialog.Builder(this).setIcon(R.mipmap.ic_launcher).setTitle(R.string.app_name)
                .setCancelable(false).setMessage("Selamat akun Sigap anda telah siap untuk digunakan!")
                .setPositiveButton("OK", (dialog, which) -> {
                    StateManager.pluck().setState(StateManager.State.LOGGED);
                    Intent intent = new Intent(this, TombolActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);
                }).show().getButton(DialogInterface.BUTTON_POSITIVE)
                .setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));
    }
}