Background stop Android player Appcelerator

I have an issue with appcelerator related to android support service. The service starts, and when I click the home button, the service is still running, and also when I click the back button. But when I remove my application from the recent list of applications (pressing the "long house" button), the service stops. This is my call service code:

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 start the service all the time, for example, that the application or something like that? Please help me, this is very important. Thanks in advance.

+4
source share
1 answer

First, let me take a quick look at your questions so that you can understand the logic.

My understanding of your question and conclusion

What you ask for is not possible even in the native application, especially if you use background services.

Why is this happening?

Because the application no longer works. The application is forcibly removed from the background and, therefore, the OS stops all of its services running in the background to clear the memory.

What most players play music by default is to use the foreground function and display a notification about the launch of the application and process something in the background (in this case, play songs).

Options you can search for

I would suggest you add a โ€œ push notification service โ€ to your application, and not engage in a โ€œ background service โ€. You will receive a notification even if your application is not in the background (same as in WhatsApp).

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

Hope this helps.

Good luck greetings

0
source

Source: https://habr.com/ru/post/1495295/


All Articles