且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在后台运行 Android 应用程序?

更新时间:2023-02-19 19:26:45

你或许可以开始一个Service 如果您希望您的应用程序在后台运行.这就是 Android 中的 Service 的用途 - 在后台运行并执行长时间操作.

You can probably start a Service here if you want your Application to run in Background. This is what Service in Android are used for - running in background and doing longtime operations.

UDPATE

您可以使用 START_STICKY 使您的服务持续运行.

You can use START_STICKY to make your Service running continuously.

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    handleCommand(intent);
    // We want this service to continue running until it is explicitly
    // stopped, so return sticky.
    return START_STICKY;
}