James Patrick
James Patrick

Reputation: 263

ScheduledExecutorService does not execute if it has moved from the main activity

I have the code below which is in ONCreate() method of the main activity and works fine. After moving to the next activity (B) which is a list view and then to activity (C ) which is the row selected from the listview and goes to sleep then the ScheduledExecutorService started in the main activity is not executing anymore .

Why is it not executing and how do I fix it? I am noob in Android .Please help me out.

Thanks in Advance .Really appreciate the help.

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

                public void run() {


    //play audio file

    mp3.start();

                }

            }, 0, 60, TimeUnit.SECONDS);

Upvotes: 0

Views: 1636

Answers (1)

baboo
baboo

Reputation: 2023

In order to cater the app running and the set sleeping scenario look in to using alarm manager with WAKELOCK... example : http://code4reference.com/2012/07/tutorial-on-android-alarmmanager/ and Alarm Manager Example

Upvotes: 1

Related Questions