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();
  • 相关阅读:
    电容
    51单片机
    三极管
    Scala 面向对象(八):特质(接口) 一
    Scala 面向对象(七):静态属性和静态方法
    Scala 面向对象(六):面向对象的特征二:继承 (一)
    Scala 面向对象(五):面向对象的特征一:封装性
    Scala 面向对象(四):import
    Scala 面向对象(三):package 包 (二)
    Scala 面向对象(二):package 包 (一) 入门
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/6298263.html
Copyright © 2011-2022 走看看