Search Android contacts more efficiently
Android Strings

Android provides a nice way of externalizing Strings in a strings.xml resource file. Using it right from the start of your project or as soon as possible is a very good idea, you might regret it later if you don't. Using XML-resources in Android is how to provide internationalization of your application. It is also good to keep all strings in one place, so you can get a nice overview of the strings shown in your application.

Speaking of Strings that are showing in your application, the content of your message String for your AlertDialogs is very questionable. If I as an user would encounter the message "f*ck ya" in an application, I would never ever give it a 5 star rating on Google Play. And it honestly does not give me a good impression of you as a person either.

The "ok" message is already defined as a string message in Android, and if your dialog button should only close the dialog then you can pass null as the listener. So therefore you can use alert.setPositiveButton(android.R.string.ok, null); which greatly improves code readability.

Readability

Speaking of code readability... I feel that you have an excessive amount of empty lines in your code, including but not restricted to:

if(C != null)

{

            alert.setPositiveButton("ok",new DialogInterface.OnClickListener() {

                @Override

                public void onClick(DialogInterface dialogInterface, int i)


        do

        {

            String display_ContactsName = getValue(C, android.provider.ContactsContract.Contacts.DISPLAY_NAME);


Instead consider this:

if(C != null)
{
    ...
    alert.setPositiveButton("ok",new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i)
    ...
        do
        {
            String display_ContactsName = getValue(C, android.provider.ContactsContract.Contacts.DISPLAY_NAME);