继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Android跳转和数据传输

Amy_木婉清
关注TA
已关注
手记 28
粉丝 2
获赞 22

显式跳转1:

Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
        startActivity(intent);

显式跳转2:

                Intent intent =new Intent();
                intent.setClass(FirstActivity.this,SecondActivity.class);
                startActivity(intent);

显示跳转3:

Intent intent = new Intent();
intent.setClassName(FirstActivity.this,"com.example.lineralayout.jump.SecondActivity");
startActivity(intent);

显式跳转4:

   Intent intent = new Intent();
   intent.setComponent(new 
   ComponentName(FirstActivity.this,"com.example.lineralayout.jump.SecondActivity"));
   startActivity(intent);

隐式跳转1:

//Manifest文件
 <activity android:name=".jump.SecondActivity"
            android:label="Second">
            <intent-filter>
                <action android:name="com.intent.test.SecondActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
//activity代码
                Intent intent = new Intent();
                intent.setAction("com.intent.test.SecondActivity");
                startActivity(intent);

数据传递:
第一个Activity:

  //显式跳转1
                Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("name","小王");
                bundle.putInt("number",25);
                intent.putExtras(bundle);
                startActivity(intent);

第二个Activity:

   mTv = findViewById(R.id.tv_title);
        Bundle bundle = getIntent().getExtras();
        String name = bundle.getString("name");
        int number = bundle.getInt("number");
        mTv.setText(name+","+number);
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP