小编SK7*_*707的帖子

如何在Android 10中从后台启动活动?

我正在构建一个Android应用,需要从后台开始活动。我正在使用ForegroundStarter来扩展Service来完成此任务。我有一个活动Adscreen.class,需要从我的前台服务中运行。活动Adscreen.class在除Android 10以外的所有Android版本上都可以正常运行(从后台开始)。

ForeGroundStarter.class

public class ForeGroundStarter extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }



    @Override
    public void onCreate() {
        super.onCreate();
        Log.d("sK", "Inside Foreground");

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.d("sK", "Inside Foreground onStartCommand");
        Intent notificationIntent = new Intent(this, Adscreen.class);
        PendingIntent pendingIntent =
                PendingIntent.getActivity(this, 0, notificationIntent, 0);


        Notification notification =
                null;

        //Launching Foreground Services From API 26+

        notificationIntent = new Intent(this, Adscreen.class);
        pendingIntent =
                PendingIntent.getActivity(this, 0, notificationIntent, 0);

        if (Build.VERSION.SDK_INT >= …
Run Code Online (Sandbox Code Playgroud)

android foreground-service

5
推荐指数
4
解决办法
288
查看次数

标签 统计

android ×1

foreground-service ×1