美文网首页程序员
Android跳转和数据传递

Android跳转和数据传递

作者: Amy木婉清 | 来源:发表于2020-08-27 14:12 被阅读0次

显式跳转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);

Fragment跳转Activity:

 getActivity().startActivity(new Intent(mContext,LabelBindingActivity.class));

相关文章

网友评论

    本文标题:Android跳转和数据传递

    本文链接:https://www.haomeiwen.com/subject/nnvfsktx.html