Skip to content

startservice in android 8.0 #31

@hong0219

Description

@hong0219

[ERROR]
Caused by java.lang.IllegalStateException
Not allowed to start service Intent { cmp=net.instiz.www.instiz/com.ixuea.android.downloader.DownloadService }: app is in background uid UidRecord{848d58 u0a186 SVC idle change:idle|uncached procs:1 proclist:32669, seq(0,0,0)}


[ URL ]
https://github.com/ixuea/android-downloader/blob/f5f5690ed0a8be1d7afacb82d2d551591ce83e04/downloader/src/main/java/com/ixuea/android/downloader/DownloadService.java


[ Code ] DownloadService.java

public static DownloadManager getDownloadManager(Context context, Config config) {
        if (!isServiceRunning(context)) {
            Intent downloadSvr = new Intent(context, DownloadService.class);
            context.startService(downloadSvr); //<---- This is Code Line 31
        }
        if (DownloadService.downloadManager == null) {
            DownloadService.downloadManager = DownloadManagerImpl.getInstance(context, config);
        }
        return downloadManager;
    }

[Suggest & How to Solve ]
DownloadService.java - getDownloadManager() -31 Line, It needs to be divided
When running the service on Android 8.0

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    context.startForegroundService(downloadSvr);
} else {
    context.startService(downloadSvr);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions