Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startservice in android 8.0 #31

Open
hong0219 opened this issue Feb 17, 2022 · 0 comments
Open

startservice in android 8.0 #31

hong0219 opened this issue Feb 17, 2022 · 0 comments

Comments

@hong0219
Copy link

hong0219 commented Feb 17, 2022

[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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant