显式与隐式启动Activity

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了显式与隐式启动Activity相关的知识,希望对你有一定的参考价值。

技术分享技术分享技术分享技术分享技术分享技术分享技术分享技术分享

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.example.metrox.l8">
 4 
 5     <application
 6         android:allowBackup="true"
 7         android:icon="@mipmap/ic_launcher"
 8         android:label="@string/app_name"
 9         android:supportsRtl="true"
10         android:theme="@style/AppTheme">
11         <activity android:name=".MainActivity">
12             <intent-filter>
13                 <action android:name="android.intent.action.MAIN" />
14                 <category android:name="android.intent.category.LAUNCHER" />
15             </intent-filter>
16         </activity>
17         <activity android:name=".MyAty" android:label="显式" />
18         <activity android:name=".HideAty" android:label="隐式" android:exported="true">
19             <intent-filter>
20                 <category android:name="android.intent.category.DEFAULT"></category>
21                 <action android:name="com.example.metrox.l8.Intent.HideAty"></action>
22             </intent-filter>
23         </activity>
24     </application>
25 
26 </manifest>
 1 package com.example.metrox.l8;
 2 
 3 import android.support.v7.app.AppCompatActivity;
 4 import android.os.Bundle;
 5 
 6 public class HideAty extends AppCompatActivity {
 7     public final  static  String ACTION = "com.example.metrox.l8.Intent.HideAty";
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.activity_hide_aty);
12     }
13 }
 1 package com.example.metrox.l8;
 2 
 3 import android.support.v7.app.AppCompatActivity;
 4 import android.os.Bundle;
 5 
 6 public class MyAty extends AppCompatActivity {
 7 
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.activity_my_aty);
12     }
13 }
 1 package com.example.metrox.l8;
 2 
 3 import android.content.DialogInterface;
 4 import android.content.Intent;
 5 import android.support.v7.app.AppCompatActivity;
 6 import android.os.Bundle;
 7 import android.view.View;
 8 import android.widget.TextView;
 9 
10 public class MainActivity extends AppCompatActivity implements View.OnClickListener {
11 
12 
13     private TextView textView;
14 
15     @Override
16     protected void onCreate(Bundle savedInstanceState) {
17         super.onCreate(savedInstanceState);
18         setContentView(R.layout.activity_main);
19 
20         textView = (TextView) findViewById(R.id.textView);
21         findViewById(R.id.button).setOnClickListener(this);
22         findViewById(R.id.button2).setOnClickListener(this);
23     }
24 
25     @Override
 1 package com.example.metrox.l9;
 2 
 3 import android.content.Intent;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 
 8 public class MainActivity extends AppCompatActivity {
 9 
10     @Override
11     protected void onCreate(Bundle savedInstanceState) {
12         super.onCreate(savedInstanceState);
13         setContentView(R.layout.activity_main);
14         findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
15             @Override
16             public void onClick(View view) {
17                 startActivity(new Intent("com.example.metrox.l8.Intent.HideAty"));
18             }
19         });
20     }
21 }

 

26     public void onClick(View view) {
27         switch (view.getId()) {
28             case R.id.button:
29                 startActivity(new Intent(MainActivity.this,MyAty.class));
30                 break;
31             case R.id.button2:
32                 startActivity(new Intent(HideAty.ACTION));
33                 break;
34         }
35     }
36 }

 

以上是关于显式与隐式启动Activity的主要内容,如果未能解决你的问题,请参考以下文章

Mysql 死锁过程及案例详解之显式与隐式锁Explicit Table Lock Implicit Table Lock

Intent显示启动与隐式启动

显式Intent与隐式Intent的使用

为啥这种显式转换的结果与隐式转换的结果不同?

显式主包与隐式主包在哪些方面表现不同?

隐式与显式接口实现[重复]