activity入门

1、前单文件

1 <activity
2     android:name="com.example.twoactivity.OtherScreenActivity"
3     android:label="@string/app_name" >
4      <intent-filter>
5     <action android:name="android.intent.action.MAIN" />
6     <category android:name="android.intent.category.LAUNCHER" />
7     </intent-filter>
8 </activity>

2、点击事件

1 方式一
2  Intent intent = new Intent();
3  intent.setClassName(this, "com.example.twoactivity.OtherScreenActivity");
4 //激活这个activity
5  startActivity(intent);
6 方式二
7 Intent intent = new Intent(this, OtherScreenActivity.class);
8 startActivity(intent);

3、继承activity的类要实现的方法

1 public class OtherScreenActivity extends Activity {
2     @Override
3     protected void onCreate(Bundle savedInstanceState) {
4         // TODO Auto-generated method stub
5         super.onCreate(savedInstanceState);
6         setContentView(R.layout.activity_two);
7     }
8 }

注:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
//中间两行代码告诉系统,要生成快捷图标;移除他们则不会在桌面系统上生成快捷图标

清单讲解

posted @ 2016-04-12 22:15  zhongyinghe  阅读(162)  评论(0)    收藏  举报