سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top