想尝试写一个应用,在开机、解锁等操作后通过广播接收器开启一个服务,可当应用正常开启时广播可正常接收,但进程被后台清理后接收不到广播,可是静态注册的广播不是在进程被杀死后也可以接收的吗,还是与启动的服务也有关系吗?求解
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<action android:name="android.intent.action.USER_PRESENT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
public class BootReceiver extends BroadcastReceiver {
Intent tuiintent=new Intent();
@Override
public void onReceive(Context context, Intent intent) {
Log.i("onreceive","onreceive");
tuiintent.setAction("android.intent.action.USER_PRESENT");
tuiintent.setPackage("com.example.notitest");
context.startService(tuiintent);
}
}