I have an activity that allows the user to select a phone number. Naturally, I would like my class to remember the identifier of the selected contact, so I save it in the class field. However, when the onActivityResult method returns, my class variable is reset. Here is what I am trying to do:
Intent intent = new Intent(Intent.ACTION_PICK, People.CONTENT_URI); startActivityForResult(intent, PICK_CONTACT); ... public void onActivityResult(int reqCode, int resultCode, Intent intent){ super.onActivityResult(reqCode, resultCode, intent); switch(reqCode){ case(PICK_CONTACT): if(resultCode == Activity.RESULT_OK){ Uri contactData = intent.getData(); Cursor c = managedQuery(contactData, null, null, null, null); if(c.moveToFirst()){ contactName = c.getString(c.getColumnIndexOrThrow(People.NAME)); contactId = c.getInt(c.getColumnIndexOrThrow(People._ID)); break;
When I set a breakpoint in this method, the values ββfor contactName and contactId will be what I expect, however as soon as the method returns, the values ββwill somehow get reset to default. It's clear that I'm missing something, but I'm not sure what I'm doing wrong or forgetting.
Thanks!
Iva
source share