Android 几种屏幕间跳转的跳转Intent Bundle
2014-03-29 22:18
330 查看
屏幕使用一个活动来实现,屏幕间是相互独立的,屏幕之间的跳转关系通过Intent来实现。屏幕间跳转分为以下几类:1. 屏幕1直接跳转到屏幕2Intent intent = new Intent();intent.setClass(屏幕1活动名.this,屏幕2活动名.class);startActivity(intent);finish(); //结束当前活动2. 屏幕1带参数跳转到屏幕2使用Bundle来传参数。例子:猜拳游戏界面:
重要代码:电脑的选择是随机的,本次联系的基本思路是,三个选项利用三个数字来代替,让电脑 随机生成一个数字,根据数字的不同来产生不同的结果。public void onClick(View v) {switch (radioGroup.getCheckedRadioButtonId()){case R.id.stone:player = 0;break;case R.id.scissors:player = 1;break;case R.id.textile:player = 2;break;default:Toast.makeText(MainActivity.this, "请选择", Toast.LENGTH_LONG).show();break;}skip();}//页面跳转private void skip(){Intent intent = new Intent();intent.setClass(MainActivity.this, ResultMainActivity.class);Bundle bundle = new Bundle();bundle.putInt("player", player);bundle.putInt("computer", new Random().nextInt(3));intent.putExtra("result", bundle);startActivity(intent);}跳转之后,要接受参数:Bundle bundle = this.getIntent().getBundleExtra("result");int playerInt = bundle.getInt("player");int computerInt = bundle.getInt("computer");猜拳游戏完整代码:
?
?
?
?
?
3. 屏幕1跳转到屏幕2,屏幕2执行结束后有返回值到屏幕1(带返回值跳转)参考示例程序:ReceiveResult(ApiDemo => App=>Activity=>ReceiveResult)重要代码://屏幕1调转到屏幕2Intent intent = new Intent(Forward.this,ForwardTargetActivity.class);startActivityForResult(intent, GET_CODE);
//在屏幕2设置返回值setResult(RESULT_OK,(new Intent()).setAction("Violet!"));finish();
//在屏幕1得到从屏幕2返回的内容@Overrideprotected void onActivityResult(int RequestCode,int ResultCode,Intent data){if(RequestCode == GET_CODE){if(ResultCode == RESULT_CANCELED){edit.append("canceled!");}else{edit.append("(okay ");edit.append(Integer.toString(ResultCode));edit.append(")");}if(data!=null){edit.append(data.getAction());}}edit.append("\n");}
重要代码:电脑的选择是随机的,本次联系的基本思路是,三个选项利用三个数字来代替,让电脑 随机生成一个数字,根据数字的不同来产生不同的结果。public void onClick(View v) {switch (radioGroup.getCheckedRadioButtonId()){case R.id.stone:player = 0;break;case R.id.scissors:player = 1;break;case R.id.textile:player = 2;break;default:Toast.makeText(MainActivity.this, "请选择", Toast.LENGTH_LONG).show();break;}skip();}//页面跳转private void skip(){Intent intent = new Intent();intent.setClass(MainActivity.this, ResultMainActivity.class);Bundle bundle = new Bundle();bundle.putInt("player", player);bundle.putInt("computer", new Random().nextInt(3));intent.putExtra("result", bundle);startActivity(intent);}跳转之后,要接受参数:Bundle bundle = this.getIntent().getBundleExtra("result");int playerInt = bundle.getInt("player");int computerInt = bundle.getInt("computer");猜拳游戏完整代码:
?
//在屏幕2设置返回值setResult(RESULT_OK,(new Intent()).setAction("Violet!"));finish();
//在屏幕1得到从屏幕2返回的内容@Overrideprotected void onActivityResult(int RequestCode,int ResultCode,Intent data){if(RequestCode == GET_CODE){if(ResultCode == RESULT_CANCELED){edit.append("canceled!");}else{edit.append("(okay ");edit.append(Integer.toString(ResultCode));edit.append(")");}if(data!=null){edit.append(data.getAction());}}edit.append("\n");}
相关文章推荐
- Android 几种屏幕间跳转的跳转Intent Bundle
- Android 几种屏幕间跳转的跳转Intent Bundle
- Android Intent 的几种跳转
- Android,使用Intent或Bundle传递参数,跳转页面。
- Android,使用Intent或Bundle传递参数,跳转页面。
- Android,使用Intent或Bundle传递参数,跳转页面
- android基础之页面间跳转传值,用Bundle+Intent
- android开发基础:Intent与Bundle的使用,实现页面跳转及信息传递
- Android,使用Intent或Bundle传递参数,跳转页面
- Cannot resolve method 'putExtra(android.os.Bundle)' Intent界面跳转传值
- Android,使用Intent或Bundle传递参数,跳转页面。
- Intent在Android中的几种用法
- Android系统Intent跳转
- Android屏幕间的跳转和事件的传递
- Android之Activity的几种跳转方式
- Android-Intent(Activity 跳转全解)
- android 平滑切换屏幕的几种方法总结
- Android用Intent和Bundle传list
- Android用Intent和Bundle传list
- [Android] Eclipse Android中设置模拟器屏幕大小几种方法