Activity related to Android Jump

Within the module normal jump

Explicit Jump

        Intent intent = new Intent();
        intent.setClass(this, xxxrActivity.class);
        intent.putExtra("key","value");
        startActivity(intent);

Jump between module

Implicit Jump

1: The specific activity jump path

        Intent intent = new Intent();
        intent.setClassName(getPackageName(), "com.xxx_xxxActivity");
        intent.putExtra("key", "value");
        if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)!= null){
            startActivity(intent);
        }else {
            Toast.makeText(this,"找不到你想要的activity",Toast.LENGTH_SHORT).show();
        }

2: The configuration of a jump action activity

		//配置action
        <activity android:name="com.xxx.xxxActivity" >
            <intent-filter>
                <action android:name="xxx" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        Intent intent = new Intent();
        intent.setPackage(getPackageName());//配置包名,防止提醒进那个同样action的activity
        intent.setAction("x'x'x");//配置的action
        intent.putExtra("key", "value");
        if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)!= null){
            startActivity(intent);
        }else {
            Toast.makeText(this,"找不到你想要的activity",Toast.LENGTH_SHORT).show();
        }

Implicit Jump security

Note: If you remove Activity location module, without removing Jump, Activity will collapse phenomenon.
So, call resolveActivity () to do judgment empty.

        if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)!= null){
            startActivity(intent);
        }else {
            Toast.makeText(this,"找不到你想要的activity",Toast.LENGTH_SHORT).show();
        }

ARouter routing Jump

Released four original articles · won praise 6 · views 235

Guess you like

Origin blog.csdn.net/yzp1121/article/details/103974091