之后我preSS home键ScheduledExecutorService的并不在后台运行 [英] after I press home button ScheduledExecutorService does not run in the background

查看:213
本文介绍了之后我preSS home键ScheduledExecutorService的并不在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的onCreate(创建此)后,我preSS home键; ScheduledExecutorService的不运行在background.Why每10分钟?

哪里是错误的。结果
请帮助我。

先谢谢了。

  ScheduledExecutorService的执行人= Executors.newSingleThreadScheduledExecutor();
        executor.scheduleWithFixedDelay(新的Runnable(){            公共无效的run(){
//播放音乐,以检查它是否执行每10分钟                  mp3.start();
            }    },0,600,TimeUnit.SECONDS);


解决方案

我认为的 AlarmManager 是更适合地重复一个任务,每10分钟比执行程序。

我建议设立一个AlarmManager并使用广播接收机能够捕获,这将触发该触发器,而你的onReceive()方法,你可以做任何你喜欢的,包括启动你的mp3里。我觉得这样会更好地为你,特别是如果你正打算为你的声音,甚至玩,如果你的应用程序不是当前设备上的应用程序有效。

I have created this in onCreate() and after I press home button ; ScheduledExecutorService does not run every 10 mins in the background.Why ?

Where is the mistake.
Please help me out .

Thanks in Advance.

        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        executor.scheduleWithFixedDelay(new Runnable(){

            public void run() {
//play music to check if it executes every 10 mins

                  mp3.start();
            }

    }, 0, 600, TimeUnit.SECONDS);

解决方案

I think that AlarmManager is more well suited to repeating a task every 10 minutes than Executor is.

I would suggest setting up an AlarmManager and using a BroadCast receiver to "catch" the trigger that it fires, and inside your onReceive() method you can do whatever you like, including start your mp3. I think this way will work better for you, especially if you are intending for you sound to play even if your application is not currently the Active app on the device.

这篇关于之后我preSS home键ScheduledExecutorService的并不在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆