Android 活动(Activity)

2018-01-27  本文已影响25人  风之化身呀

1、新建的任何新活动都应该重写其onCreate方法
2、所有活动都要在Android-Manifest.xml中注册才能使用
3、活动的注册声明要放在application标签内,并通过activity活动对其注册,activity的name字段用来指定注册哪个活动

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

    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:name="org.litepal.LitePalApplication"
        android:allowBackup="true"
        android:icon="@mipmap/logo"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>          //主活动(程序入口)
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

         <activity android:name=".WeatherActivity" />     // 非主活动
    </application>

</manifest>

4、多活动就是多个页面,android中活动之间的切换是通过Intent实现的,Intent分为显式和隐式

            Intent intent = new Intent(HellowRNActivity.this,FirstActivity.class);    //沟通两个activity的桥梁
            startActivity(intent);
Intent intent=new Intent('com.example.activitytest.ACTION_START',android.intent.category.DEFAULT)

每个Intent只能指定一个action,但可以指定多个category:

Intent intent=new Intent('com.example.activitytest.ACTION_START',android.intent.category.DEFAULT)
intent.addCategory('com.example.activitytest.MY_CATEGORY')

Activity之间还可以通过Intent的putExtra('key',value)和getStringExtra来传递数据
5、活动的生命周期

上一篇下一篇

猜你喜欢

热点阅读