Intent运动方式.docxVIP

  • 1
  • 0
  • 约1.2万字
  • 约 12页
  • 2017-07-09 发布于河南
  • 举报
Intent运动方式

1.无参数Activity跳转Intent it = new Intent(Activity.this, Activity2.class); startActivity(it); 2.向下一个Activity传递数据(使用Bundle或Intent.putExtras)Intent it = new Intent(Activity.this, Activity2.class); Bundle bundle=new Bundle(); bundle.putString(name, This is from MainActivity!); it.putExtras(bundle); // it.putExtra(“test”, shuju”); startActivity(it); // startActivityForResult(it,REQUEST_CODE); 相应的对于数据的获取可以采用:Bundle bundle=getIntent().getExtras(); String name=bundle.getString(name); 如果activity设为singletask,那么接收数据时也要实现onNewIntent()方法3.向上一个Activity返回结果(使用setResult,针对startActivityForResult(it,REQUEST_CODE)启动的Activity)Intent intent=getIntent(); Bundle bundle2=new Bundle(); bundle2.putString(name, This is from ShowMsg!); intent.putExtras(bundle2); setResult(RESULT_OK, intent); 4.回调上一个Activity的结果处理函数(onActivityResult)@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (requestCode==REQUEST_CODE){ if(resultCode==RESULT_CANCELED) setTitle(cancle); else if (resultCode==RESULT_OK) { String temp=null; Bundle bundle=data.getExtras(); if(bundle!=null) temp=bundle.getString(name); setTitle(temp); } } } 5、显示网页Uri uri = Uri.parse(); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); 6、显示地图Uri uri = Uri.parse(geo:38.899533,-77.036476); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); //其他 geo URI //geo:latitude,longitude //geo:latitude,longitude?z=zoom //geo:0,0?q=my+street+address //geo:0,0?q=business+near+city //google.streetview:cbll=lat,lngcbp=1,yaw,,pitch,zoommz=mapZoom 7、路径规划Uri uri = Uri.parse(/maps?f=dsaddr=startLat%0startLngdaddr=endLat%0endLnghl=en); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); //where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456 8、打电话// 叫出拨号程序Uri uri = Uri.parse(tel:0800000123);Intent it = new Intent(Intent.ACTION_DIAL, uri);startActivity(it);// 直

文档评论(0)

1亿VIP精品文档

相关文档