zoukankan      html  css  js  c++  java
  • android开发学习——day5

      活动跳转部分代码显式intent

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.first_layout);
            Button button1=(Button)findViewById(R.id.button_1);
            button1.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View v){
                    //Toast.makeText(FirstActivity.this,"You clicked Button 1",
                           // Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
                    startActivity(intent);
                }
            });
        }

      隐式intent跳转,设置category

    public void onClick(View v){
                    //Toast.makeText(FirstActivity.this,"You clicked Button 1",
                           // Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent("com.example.hs769.activitytest.ACTION_START");
                    intent.addCategory("com.example.hs769.activitytest.MY_CATEGORY");
                    startActivity(intent);
                }
    <intent-filter>
                    <action android:name="com.example.hs769.activitytest.ACTION_START"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                    <category android:name="com.example.hs769.activitytest.MY_CATEGORY"/>
                </intent-filter>

      开浏览器

    <activity android:name=".ThirdActivity">
                <intent-filter>
                    <action android:name="android.intent.action.VIEW"/>
                    <category android:name="android.intent.category.DEFAULT"/>
                    <data android:scheme="http"/>
                </intent-filter>
            </activity>
    public void onClick(View v){
                    //Toast.makeText(FirstActivity.this,"You clicked Button 1",
                           // Toast.LENGTH_SHORT).show();
                    Intent intent=new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse("http://www.baidu.com"));
                    //intent.addCategory("com.example.hs769.activitytest.MY_CATEGORY");
                    startActivity(intent);
                }

      利用intent向活动传参,正向

    public void onClick(View v){
                    String data="Hello SecondActivity";
                    Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
                    intent.putExtra("extra_data",data);
                    startActivity(intent);
                }
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.second_layout);
            Intent intent=getIntent();
  • 相关阅读:
    基于Freescale的主流芯片HCS08
    BizTalk Server 2010 映射器(Mapper) [ 下篇 ]
    BizTalk Server 2010 使用 WCF Service [ 中篇 ]
    Ext JS 4 Beta 1发布了
    Step by Step WebMatrix网站开发之一:Webmatrix安装
    REST WebService与SOAP WebService的比较
    BizTalk Server 2010 使用 WCF Service [ 上篇 ]
    BizTalk Server 2010 映射器(Mapper) [ 中篇 ]
    BizTalk Server 2010 映射器(Mapper) [ 上篇 ]
    ExtJS 4 Beta 2预览:Ext.Brew包
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/6298263.html
Copyright © 2011-2022 走看看