• 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();
  • 相关阅读:
    【leetcode 简单】第六题 有效的括号
    【leetcode 简单】第四题 罗马数字转整数
    【leetcode 简单】第三题 回文数
    【leetcode 简单】第二题 反转整数
    【leetcode 简单】第一题 两数之和
    C语言实现栈(顺序存储方式)
    C语言实现线性表(链式存储方式)
    【Linux 命令】fping ping 包间隔时间详解
    有趣的模式见解
    解决在web项目使用log4j中无法将log信息写入文件
  • 原文地址:https://www.cnblogs.com/wangtianning1223/p/6298263.html
Copyright © 2020-2023  润新知