4

I have a problem with appcelerator, regarding to android background service. The service starts, and when I press the home button, the service is still running, and also when I click the back button. But when I remove my app from the recent apps list(pressing long home button) , the service stops. This is my code for the call service:

var SECONDS = 6;
    // every 10 minutes
    var intent = Titanium.Android.createServiceIntent({
        url : 'myservice.js'
    });
    intent.putExtra('interval', SECONDS * 1000);
    intent.putExtra('message_to_echo', num);

    //in millimeter
    var service = Titanium.Android.createService(intent);

    service.addEventListener('resume', function(e) {
    //  num++;
    //  alert(num);
    });

    service.start();    

And this is the file service code:

var service = Titanium.Android.currentService;
var intent = service.intent;
var message = intent.getStringExtra("message_to_echo");

var intent = Ti.Android.createIntent({
    flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
    // Substitute the correct classname for your application
    className : 'com.mappa.angeli.MappaActivity',
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);

// Create a PendingIntent to tie together the Activity and Intent
var pending = Titanium.Android.createPendingIntent({
    intent: intent,
    flags: Titanium.Android.FLAG_UPDATE_CURRENT
});

// Create the notification
var notification = Titanium.Android.createNotification({
    // icon is passed as an Android resource ID -- see Ti.App.Android.R.
   // icon: Ti.App.Android.R.drawable.my_icon,
    contentTitle: 'Something Happened',
    contentText : 'Click to return to the application.',
   // tickerText: 'Our app made a notification!',
    defaults:Titanium.Android.NotificationManager.DEFAULT_SOUND,
    contentIntent: pending
});
// Send the notification.
Titanium.Android.NotificationManager.notify(0, notification);

How can I run the service continously, such as whats app or something like that? Please help me, it's very important. Thanks in advance!!!

Hel00
  • 127
  • 1
  • 10
  • This is currently not possible with Appcelerator. Even though native app are doing it. There are similar post of this requirement, Still no reliable answer. – Sharif Abu Darda Feb 08 '16 at 08:15

1 Answers1

0

First let me give you a little perspective about your questions so that you'll be able to understand the logic behind.

My Understanding about your Question and Conclusion

What you are asking for is not possible even in the native app, specifically if you are using the background services.

Why it is doing so?

Because the application is no longer in service anymore. The app is forcefully removed from the background and hence the OS stops all its services running in the background to clear the Memory.

What most of the default players do to play music is the use the foreground service and show a notification that the app is running and is processing something in the background (in this case playing the songs).

Options that you could look for

I would suggest you to add up 'push notification service' to your app rather than going in for 'background service'. You will get the notification even if your app is not in the background (same as it is in WhatsApp).

You could follow the below link to implement the GCM push services for android: http://www.tidev.io/2013/12/20/using-gcm-for-android-push-notifications-with-acs/

Hope this helps.

Good Luck, Cheers

A. A. Sebastian
  • 540
  • 1
  • 7
  • 19