【发布时间】:2015-11-05 07:46:10
【问题描述】:
也许有人可以帮助我。我想将两个字符串传递给另一个活动。这是我生成字符串的代码:
private void contactPicked(Intent data) {
Cursor cursor = null;
try {
String phoneNo = null;
String name = null;
// getData() method will have the Content Uri of the selected contact
Uri uri = data.getData();
//Query the content uri
cursor = getContentResolver().query(uri, null, null, null, null);
cursor.moveToFirst();
// column index of the phone number
int phoneIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
// column index of the contact name
int nameIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
phoneNo = cursor.getString(phoneIndex);
name = cursor.getString(nameIndex);
// Set the value to the textviews
textView1.setText(name);
textView2.setText(phoneNo);
} catch (Exception e) {
e.printStackTrace();
}
我想将 phoneNo 和 Name 传递给我的 MainActivity
我尝试做一个 SharedPreference 并在我的 MainAcitivity 中加载 DefaultSharedPreference 而没有任何结果
【问题讨论】: