java - 安装后如何永远运行应用程序?
问题描述
我想在安装后在后台运行我的 android 应用程序。我尝试在后台运行应用程序。但是我必须在重启设备后自己启动应用程序。我需要的是我需要将我的应用程序作为 FACEBOOK,whatsapp 来工作。据我所知,它们永远在后台运行,并且每次重新启动后都不需要手动重新启动。有人帮我吗?
解决方案
在 AndroidManifest.xml 中
<receiver android:name=".BootUpReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
创建以 BootUpReceiver 命名的 Java 文件
public class BootUpReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
//Do your coding here...
}
}
}
推荐阅读
- c++ - 使用 C++ 解密文本
- python-3.x - ev_loop 在 asyncio.sleep 之后不会继续
- php - 如何使用 PHP 提取网页中的单个链接?
- ios - 如何在应用商店的定价和可用性部分选择价格?
- python - Python 使用请求登录,但无法获得完整页面
- c# - 在 C# 中使用 LINQ 在数独板上获取 3x3 组
- java - 使用 aws-sdk-java 通过流式传输将多部分文件上传到 Amazon S3 时内存使用率高
- r - data.frame 中列中先前值的平均值
- c++ - 向后迭代 LED 时,FastLED 库不工作
- swift - 使用 Swift 从数字数组中获取非重复数字数组