title: How to refresh list view after adding the contact from contact intent?
body: <p>I have an activity in which I am showing the contacts from phone in a list view. Now I have added function of adding the new contact by calling the contact intent to add a new contact. This is done nicely. </p>
  
  <p>But when I get return to the activity after adding the contact I can not see the latest added contact. </p>
  
  <p>I tried to refresh the list view by calling invalidate() also on adapter I tried by calling invalidate() onResume method. </p>
  
  <p>But I can not get the result. I also tried to call the add intent with startActivityForResult and get the contacts in the onActivityResult() but that also failed. </p>
  
  <p>Don't know what's going  wrong. Please help. </p>
  
  <p>Activity:</p>
  
  <pre><code>public class ContactList extends AppCompatActivity {
  
  
      private ArrayList&lt;contact&gt; contact_list = null;
      private contactAdapter mContactAdapter = null;
  
      private ArrayList&lt;contact&gt; items;
      private ArrayList&lt;contact&gt; selectedContacts;
      boolean[] isChecked;
      Cursor mCursor;
      ListView lv;
      public int RQS_PICK_CONTACT = 1,RQS_ADD_CONTACT = 2;
      private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 100;
      ArrayList&lt;Integer&gt; selectedItemsPositions;
      private ImageView done,back;
      private boolean mContactListActivity;
      private FloatingActionButton fab;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_contacts_list);
  
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  
          toolbar.setTitle("");
          TextView toolbarTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
  
          toolbarTitle.setText("Select Contacts");
  
          setSupportActionBar(toolbar);
  
          done = (ImageView)findViewById(R.id.done);
  
          back = (ImageView)findViewById(R.id.back);
  
          fab = (FloatingActionButton)findViewById(R.id.fab);
  
          contact_list = new ArrayList&lt;contact&gt;();
  
          selectedContacts = new ArrayList&lt;contact&gt;();
  
       //   selectedItemsPositions = new ArrayList&lt;&gt;();
  
          lv = (ListView)findViewById(R.id.list);
  
          showContacts();
  
          //getContacts();
  
  
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
                  Intent intent = new Intent(Intent.ACTION_INSERT,
                          ContactsContract.Contacts.CONTENT_URI);
                  startActivityForResult(intent,RQS_ADD_CONTACT);
  
  
              }
          });
  
  
      }
  
      @SuppressWarnings("unused")
      private void getContacts() {
  
  
          String[] projection = new String[] {
                  ContactsContract.Contacts.DISPLAY_NAME,
                  ContactsContract.Contacts.HAS_PHONE_NUMBER,
                  ContactsContract.Contacts._ID };
  
  
         mCursor = managedQuery(ContactsContract.Contacts.CONTENT_URI, null, null, null, "upper("+ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");
  
          while (mCursor.moveToNext()) {
              contact contact = new contact();
  
              String contactId = mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts._ID));
  
              contact.setContactid(mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts._ID)));
              contact.setContactName(mCursor.getString(mCursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));
              contact_list.add(contact);
          }
          isChecked = new boolean[mCursor.getCount()];
  
          for (int i = 0; i &lt; isChecked.length; i++) {
              isChecked[i] = false;
          }
  
  
          this.mContactAdapter = new contactAdapter(this, R.layout.contact_list_item, contact_list);
          lv.setAdapter(this.mContactAdapter);
          mContactAdapter.notifyDataSetChanged();
       //   mCursor.close();
  
      }
  
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode == RQS_PICK_CONTACT) {
              if (resultCode == RESULT_OK) {
  
                  getContacts();
  
              }
          }
  
      }
  
  
      @Override
      public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                             int[] grantResults) {
          if (requestCode == PERMISSIONS_REQUEST_READ_CONTACTS) {
              if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                  // Permission is granted
                  getContacts();
              } else {
                  Toast.makeText(this, "Until you grant the permission, we canot display the names", Toast.LENGTH_SHORT).show();
              }
          }
      }
  
  
      private void showContacts()
      {
          if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M &amp;&amp; checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
  
              requestPermissions(new String[]{Manifest.permission.READ_CONTACTS}, PERMISSIONS_REQUEST_READ_CONTACTS);
              //After this point you wait for callback in onRequestPermissionsResult(int, String[], int[]) overriden method
          }
  
          else {
  
              getContacts();
  
          }
  
      }
  
      @Override
      public void onResume()
      {
  
          super.onResume();
  
          mContactAdapter.notifyDataSetInvalidated();
  
          //Intent intent = getIntent();
          //intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
          //finish();
          //startActivity(intent);
  
      }
  
  }
  </code></pre>