Android 开机启动广播服务 BroadCastReceiver
程序员文章站
2022-06-30 16:34:48
...
public class StartupReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent in = new Intent();
in.setClass(context, Basic.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
}
AndroidManifest.xml配置:
<receiver android:name=".StartReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
{
@Override
public void onReceive(Context context, Intent intent)
{
Intent in = new Intent();
in.setClass(context, Basic.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);
}
}
AndroidManifest.xml配置:
<receiver android:name=".StartReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
上一篇: 冒泡排序概念实例