其他分享
首页 > 其他分享> > Activity跳转显示及隐式方法

Activity跳转显示及隐式方法

作者:互联网

 1 public class AActivity extends AppCompatActivity {
 2     private Button btnJump;
 3     @Override
 4     protected void onCreate(Bundle savedInstanceState) {
 5         super.onCreate(savedInstanceState);
 6         setContentView(R.layout.activity_aactivity);
 7         btnJump=findViewById(R.id.jump);
 8         btnJump.setOnClickListener(new View.OnClickListener() {
 9             @Override
10             public void onClick(View view) {
11                 //显式跳转方法1
12                 Intent intent=new Intent(AActivity.this,BActivity.class);
13                 startActivity(intent);
14 
15                 //显式跳转方法二
16                 //Intent intent=new Intent();
17                 //intent.setClass(AActivity.this,BActivity.class);
18                 //startActivity(intent);
19 
20                 //显示跳转方法三
21                 //Intent intent=new Intent();
22                 //intent.setClassName(AActivity.this, "com.example.first.jump.BActivity");
23                 //startActivity(intent);
24 
25                 //显式跳转方法四
26                 //Intent intent=new Intent();
27                 //intent.setComponent(new ComponentName(AActivity.this, "com.example.first.jump.BActivity"));
28                 //startActivity(intent);
29 
30                 //隐式跳转
31                 //Intent intent=new Intent();
32                 //intent.setAction("com.example.test.BActivity");
33                 //startActivity(intent);
34                 //隐式跳转需要在AndroidMainifest.xml文件中要跳转的activity下设置<intent-filter>标签,像这样
35                 /*<intent-filter>
36                     <action android:name="com.example.test.BActivity" />
37 
38                     <category android:name="android.intent.category.DEFAULT" />
39                 </intent-filter>/>*/
40             }
41         });
42     }
43 }

 

标签:AActivity,startActivity,跳转,new,Intent,Activity,intent,隐式
来源: https://www.cnblogs.com/konglong-cm/p/15860110.html