首页 > 解决方案 > 安装后如何永远运行应用程序?

问题描述

我想在安装后在后台运行我的 android 应用程序。我尝试在后台运行应用程序。但是我必须在重启设备后自己启动应用程序。我需要的是我需要将我的应用程序作为 FACEBOOK,whatsapp 来工作。据我所知,它们永远在后台运行,并且每次重新启动后都不需要手动重新启动。有人帮我吗?

标签: javaandroidandroid-background

解决方案


在 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...
         }
    }
}

推荐阅读