Intent 7大属性之一:ComponentName

package com.lxj.day06_intent;

import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
    //声明控件
    private Button show_next;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //1、初始化控件
        show_next = (Button) findViewById(R.id.show_next);
        
        show_next.setOnClickListener(new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                // 给Intent设置ComponentName属性
                ComponentName cn = new ComponentName(MainActivity.this,BActivity.class);
                //第二步:将ComponentName设置到intent中
                Intent intent = new Intent();
                intent.setComponent(cn);
                //第三步:startActivity(intent)
                startActivity(intent);
            }
        });
    }
}
----------------------------------------------------------------------------------------------
package com.lxj.day06_intent;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class BActivity extends Activity {
    private Button show_next;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bactivity_main);
       
        show_next = (Button) findViewById(R.id.show_next);
       
        show_next.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
              
                ComponentName cn = new ComponentName(BActivity.this,CActivity.class);
                Intent intent = new Intent();
                intent.setComponent(cn);
                startActivity(intent);
            }
        });
    }
}

---------------------------------------------------------------------------------------------
package com.lxj.day06_intent;

import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class CActivity extends Activity {

    private Button show_next;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cactivity_main);
        show_next = (Button) findViewById(R.id.show_next);
       
        show_next.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                ComponentName cn = new ComponentName(CActivity.this , DActivity.class);
                Intent intent = new Intent();
                intent.setComponent(cn);
                startActivity(intent);
            }
        });
    }
}
---------------------------------------------------------------------------------------------
package com.lxj.day06_intent;

import android.os.Bundle;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class DActivity extends Activity {
    private Button show_next;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dactivity_main);
        show_next = (Button) findViewById(R.id.show_next);
        show_next.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                ComponentName cn = new ComponentName(DActivity.this,CActivity.class);
                Intent intent = new Intent();
                intent.setComponent(cn);
                startActivity(intent);
            }
        });
    }
}

----------------------------------------------------------------------------------------------<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="这是MainActivity" />

    <Button
        android:id="@+id/show_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:text="跳转到下个Activity"
        />
</LinearLayout>
----------------------------------------------------------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="这是BActivity" />

    <Button
        android:id="@+id/show_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:text="跳转到下个Activity"
        />
</LinearLayout>
----------------------------------------------------------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="这是CActivity" />

    <Button
        android:id="@+id/show_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:text="跳转到下个Activity"
        />
</LinearLayout>
----------------------------------------------------------------------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="这是DActivity" />

    <Button
        android:id="@+id/show_next"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
         android:text="跳转到下个Activity"
        />
</LinearLayout>
--------------------------------------AndroidMainfest.xml-----------------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.qf.day06_intent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.qf.day06_intent.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
         <activity android:name=".BActivity"></activity>
        <activity android:name=".CActivity"></activity>
        <activity android:name=".DActivity"></activity>
    </application>

</manifest>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值