Android day_09 (Activity人品计算器案例)

这篇博客介绍了Android中Activity的启动方式,包括隐式和显示意图的应用。重点讲解了人品计算器案例,通过MainActivity使用显示意图跳转到ResultActivity,并在跳转过程中传递数据。
摘要由CSDN通过智能技术生成
1)两种意图(intent):

【1】开启自己应用的界面用显示意图

【2】开启其他应用(系统应用)的时候用隐示意图 例如电话拨号器

【3】显示意图更安全

1.隐示意图:

定义:通过指定一组动作或者数据

意图过滤器<intent-filter>可以有多个,只要匹配上一个意图过滤器<intent-filter>就可以

  //设置意图
        Intent intent = new Intent();
        //设置跳转动作
        intent.setAction("tlb");
        //设置Category
        intent.addCategory("android.intent.category.DEFAULT");
//        //设置数据
//        intent.setData(Uri.parse("tlb:"+110));
//        //设置数据类型
//        intent.setType("aa/bb");
        //注意:如果setData和setType一起使用  应该用下面这个方法
        intent.setDataAndType(Uri.parse("tlb:" + 110), "aa/bb");
        startActivity(intent);

2.显示意图:

定义:通过指定具体的包名和类名


                
package ymq.demo03; import android.app.Activity; import android.os.Bundle; import android.view.*; import android.widget.*; public class demo03 extends Activity { /** Called when the activity is first created. */ String str=""; EditText et; int c=0,flag=0; double b=0.0,g=0.0,f=0.0; View vi; public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0, 1, 1, "退出"); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { // TODO Auto-generated method stub if(item.getItemId()==1){finish();} return super.onOptionsItemSelected(item); } //计算方法 public double calculater(){ switch(c){ case 0:f=g;break; case 1:f=b+g;break; case 2:f=b-g;break; case 3:f=b*g;break; case 4:f=b/g;break; } b=f; c=0; return f; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获得按键 final Button number[]=new Button[10]; final Button fuhao[]=new Button[11]; fuhao[0]=(Button)findViewById(R.id.button01); fuhao[1]=(Button)findViewById(R.id.button02); fuhao[2]=(Button)findViewById(R.id.button03); fuhao[3]=(Button)findViewById(R.id.button04); fuhao[4]=(Button)findViewById(R.id.button05); fuhao[5]=(Button)findViewById(R.id.button06); fuhao[6]=(Button)findViewById(R.id.buttonce); fuhao[7]=(Button)findViewById(R.id.buttonc); fuhao[8]=(Button)findViewById(R.id.zheng); fuhao[9]=(Button)findViewById(R.id.kaifang); fuhao[10]=(Button)findViewById(R.id.pingfang); number[0]=(Button)findViewById(R.id.button0); number[1]=(Button)findViewById(R.id.button1); number[2]=(Button)findViewById(R.id.button2); number[3]=(Button)findViewById(R.id.button3); number[4]=(Button)findViewById(R.id.button4); number[5]=(Button)findViewById(R.id.button5); number[6]=(Button)findViewById(R.id.button6); number[7]=(Butto
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值