0

I made an activity which reads all my contacts and put the names into an Arraylist. This ArrayList is used to fill up my ListView. If I'll click on an item in this ListView the app will search in my contacts for the name and start an Activity with putting the name and number through intent.putExtra. The Chat is stored with tinyDB (https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo/blob/master/TinyDB.java) which takes the phonenumber as the key.

All works fine but one scenario breaks this concept. If I have one contact with multiple phone numbers and I'll click on him in the ListView my code is going to search for the name in my contacts and take this number to start the chat. So the chat will be started with the phone number of the contact which my code will find first every time. So it is impossible to start the chat activity with the second phone number.

So I thought I should put the phone number into the arraylist too but then they will shown up in the ListView.

Some advices?

Jones
  • 141
  • 1
  • 9

2 Answers2

0

if you are making a chat application this answer might help.

how do apps like whatsapp show contacts that are only using app

To keep it simple You can do it fetch the contacts in the background using Async Read more about async here.

Async Task

Normalize the number you can use googlelibphoneLib to do so.

Google Lib Phone Number

and save them in SQLite.

recnac
  • 3,744
  • 6
  • 24
  • 46
Malik Saifullah
  • 522
  • 1
  • 6
  • 22
0

You have a couple of bad assumptions there, note the following:

  1. A contact may have zero, one or multiple phones, and you need to handle all 3 cases.
  2. A contact name is not unique, and you may have 2 or more "John" in your contacts list.
  3. A phone number may be stored within more then one contact (think of a home phone number that is shared between a married couple)

When passing around search keys between your different activities, you must use a unique identifier that identified exactly the selected item, like a Contact-ID, or a position in the list.

In your main list two options come to mind: either show a list item per phone and not per contact, or when a contact is clicked and it has more then one phone, show an AlertDialog asking the user to select which phone to use.

marmor
  • 27,641
  • 11
  • 107
  • 150