Android DroidGap Service Keep App Running

265 views Asked by At

I am developing an app using PhoneGap system. Currently when the user switch to another app and then come back to the app, it starts from scratch as if the user is opening it once again.

Now I have heard of the Service that android has but since my class is already extended, I cannot extend it with Service. Do you know of any solution that I can do to solve this small problem.

Currently my code is as follows:

public class MainActivity extends DroidGap {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.init();

        super.setBooleanProperty("keepRunning", true);

        super.setIntegerProperty("loadUrlTimeoutValue", 50000); 
        super.loadUrl("file:///android_asset/www/index.html",50000);
     }
}

Thanks,

Keith Spiteri

1

There are 1 answers

1
Rodrigo Brun On BEST ANSWER

Open your config.xml in "res/xml/config.xml" and locate for "preference" tags.

Add this line/tag before or after other preferences tags.

<preference name="keepRunning" value="true" />

This is a solution for your question, it's simple, the app will keep running when your application is hidden, and he'll close when you close the application.

It's it. I hope I helped you.

Att. Rodrigo