Intent 7大属性之一:ComponentName
2016-01-05 19:28
513 查看
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>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件