首页 > 代码库 > startActivityForResult and onActivityResult
startActivityForResult and onActivityResult
startActivityForResult and onActivityResult
startActivityForResult 开启Activity 组织数据之后 发送,onActivityResult 接受数据
1 public class MyActivity extends Activity { 2 ... 3 4 static final int PICK_CONTACT_REQUEST = 0; 5 6 protected boolean onKeyDown(int keyCode, KeyEvent event) { 7 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { 8 // When the user center presses, let them pick a contact. 9 startActivityForResult(10 new Intent(Intent.ACTION_PICK,11 new Uri("content://contacts")),12 PICK_CONTACT_REQUEST);13 return true;14 }15 return false;16 }17 18 protected void onActivityResult(int requestCode, int resultCode,19 Intent data) {20 if (requestCode == PICK_CONTACT_REQUEST) {21 if (resultCode == RESULT_OK) {22 // A contact was picked. Here we will just display it23 // to the user.24 startActivity(new Intent(Intent.ACTION_VIEW, data));25 }26 }27 }
startActivityForResult and onActivityResult
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。