前言:我理解静态广播生效必须是在app被拉起来之后,所以应该是Application的逻辑先生效,静态广播的处理后生效,即Application起来如果太耗时的话会影响静态广播的处理,测试一下先后顺序
1.demo
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo_164_receiver_application">
<application
android:allowBackup="true"
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
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>
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.LOCALE_CHANGED"/>
</intent-filter>
</receiver>
</application>
</manifest>
receiver
package com.example.demo_164_receiver_application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
Log.d("jiatai", "the receiver receive broadcast");
}
}
application
package com.example.demo_164_receiver_application;
import android.app.Application;
import android.util.Log;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Log.d("jiatai", "MyApplication onCreate");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
2.测试
我比较担心Android O对静态广播的测试,按理说普通app对静态广播的管控应该很严,不光Google会管控,手机厂商应该也会。
测试了下启动广播和语音改变广播都收不到
测试待续,后面用系统应用测一下