我有两个单独startActivityForResult
的 s,它们利用不同的活动。我希望能够在我的主要活动中处理这些活动的结果。
然而,当返回主活动时,该功能被执行(例如,在 requestCodeText 的情况下,btn3 上的文本被设置为正确的值)但随后应用程序冻结。
这是我的代码:
final int request_CodeNumber = 1;
final int request_CodeText = 2;
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case request_CodeText:
Uri uri = data.getData();
final Button btn3 = (Button)findViewById(R.id.btnMessage);
if(resultCode == RESULT_OK) {
btn3.setText((String) uri.toString());
}
break;
case request_CodeNumber:
Uri uri2 = data.getData();
Cursor c = null;
try {
c = getContentResolver().query(uri2, new String[]{
ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
null, null, null);
if (c!= null && c.moveToFirst()) {
String number = c.getString(0);
int type = c.getInt(1);
String contactName = c.getString(2);
showSelectedNumber(type, number, contactName);
}
} finally {
if (c != null) {
c.close();
}
}
break;
}
}
我在 logcat 中得到以下信息:
11-20 21:52:45.155: D/dalvikvm(655): GC_FOR_ALLOC freed 66K, 4% free 8004K/8259K, paused 85ms, total 97ms
11-20 21:52:45.215: I/dalvikvm-heap(655): Grow heap (frag case) to 10.633MB for 2903056-byte allocation
11-20 21:52:45.485: D/dalvikvm(655): GC_CONCURRENT freed <1K, 3% free 10838K/11143K, paused 122ms+20ms, total 273ms
11-20 21:52:47.055: D/libEGL(655): loaded /system/lib/egl/libEGL_emulation.so
11-20 21:52:47.076: D/(655): HostConnection::get() New Host Connection established 0x2a0d7d68, tid 655
11-20 21:52:47.218: D/libEGL(655): loaded /system/lib/egl/libGLESv1_CM_emulation.so
11-20 21:52:47.236: D/libEGL(655): loaded /system/lib/egl/libGLESv2_emulation.so
11-20 21:52:47.425: W/EGL_emulation(655): eglSurfaceAttrib not implemented
11-20 21:52:47.476: D/OpenGLRenderer(655): Enabling debug mode 0
11-20 21:52:54.076: W/EGL_emulation(655): eglSurfaceAttrib not implemented
11-20 21:52:59.646: W/EGL_emulation(655): eglSurfaceAttrib not implemented